Skip to content

Commit

Permalink
tests: destroying view after tests
Browse files Browse the repository at this point in the history
  • Loading branch information
satanTime committed Mar 27, 2022
1 parent 4f2b745 commit b99b535
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions tests/issue-1596/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
Component,
ComponentFactoryResolver,
NgModule,
OnDestroy,
Optional,
ViewContainerRef,
} from '@angular/core';
Expand All @@ -13,23 +14,29 @@ import { MockBuilder, ngMocks } from 'ng-mocks';
selector: 'parent',
template: '<div #parent>parent</div>',
})
class ParentComponent {
class ParentComponent implements OnDestroy {
private readonly vcr: ViewContainerRef;

public constructor(
viewContainerRef: ViewContainerRef,
@Optional() componentFactoryResolver: ComponentFactoryResolver,
) {
const vcr: any = viewContainerRef;
this.vcr = viewContainerRef;

try {
vcr.createComponent(ChildComponent);
} catch (e) {
(this.vcr as any).createComponent(ChildComponent);
} catch {
const factory =
componentFactoryResolver.resolveComponentFactory(
ChildComponent,
);
vcr.createComponent(factory);
(this.vcr as any).createComponent(factory);
}
}

public ngOnDestroy(): void {
this.vcr.clear();
}
}

@Component({
Expand Down

0 comments on commit b99b535

Please sign in to comment.