Skip to content

Commit b99b535

Browse files
committed
tests: destroying view after tests
1 parent 4f2b745 commit b99b535

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

tests/issue-1596/test.spec.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
Component,
33
ComponentFactoryResolver,
44
NgModule,
5+
OnDestroy,
56
Optional,
67
ViewContainerRef,
78
} from '@angular/core';
@@ -13,23 +14,29 @@ import { MockBuilder, ngMocks } from 'ng-mocks';
1314
selector: 'parent',
1415
template: '<div #parent>parent</div>',
1516
})
16-
class ParentComponent {
17+
class ParentComponent implements OnDestroy {
18+
private readonly vcr: ViewContainerRef;
19+
1720
public constructor(
1821
viewContainerRef: ViewContainerRef,
1922
@Optional() componentFactoryResolver: ComponentFactoryResolver,
2023
) {
21-
const vcr: any = viewContainerRef;
24+
this.vcr = viewContainerRef;
2225

2326
try {
24-
vcr.createComponent(ChildComponent);
25-
} catch (e) {
27+
(this.vcr as any).createComponent(ChildComponent);
28+
} catch {
2629
const factory =
2730
componentFactoryResolver.resolveComponentFactory(
2831
ChildComponent,
2932
);
30-
vcr.createComponent(factory);
33+
(this.vcr as any).createComponent(factory);
3134
}
3235
}
36+
37+
public ngOnDestroy(): void {
38+
this.vcr.clear();
39+
}
3340
}
3441

3542
@Component({

0 commit comments

Comments
 (0)