bar<\/span><\/leaf><\/div>/);
- });
-
- it('should encapsulate host and children with different attributes', () => {
- class WrapperComponentWith {
- static ngComponentDef = ɵɵdefineComponent({
- type: WrapperComponentWith,
- selectors: [['wrapper']],
- consts: 1,
- vars: 0,
- template: function(rf: RenderFlags, ctx: WrapperComponentWith) {
- if (rf & RenderFlags.Create) {
- ɵɵelement(0, 'leaf');
- }
- },
- factory: () => new WrapperComponentWith,
- encapsulation: ViewEncapsulation.Emulated,
- styles: [],
- data: {},
- directives: () => [LeafComponentwith]
- });
- }
-
- class LeafComponentwith {
- static ngComponentDef = ɵɵdefineComponent({
- type: LeafComponentwith,
- selectors: [['leaf']],
- consts: 2,
- vars: 0,
- template: function(rf: RenderFlags, ctx: LeafComponentwith) {
- if (rf & RenderFlags.Create) {
- ɵɵelementStart(0, 'span');
- { ɵɵtext(1, 'bar'); }
- ɵɵelementEnd();
- }
- },
- factory: () => new LeafComponentwith,
- encapsulation: ViewEncapsulation.Emulated,
- styles: [],
- data: {},
- });
- }
-
- renderComponent(WrapperComponentWith, {rendererFactory: getRendererFactory2(document)});
- expect(containerEl.outerHTML)
- .toMatch(
- /bar<\/span><\/leaf><\/div>/);
- });
-
});
describe('recursive components', () => {
@@ -671,42 +548,3 @@ describe('recursive components', () => {
});
});
-
-describe('view destruction', () => {
- it('should invoke onDestroy when directly destroying a root view', () => {
- let wasOnDestroyCalled = false;
-
- class ComponentWithOnDestroy {
- static ngComponentDef = ɵɵdefineComponent({
- selectors: [['comp-with-destroy']],
- type: ComponentWithOnDestroy,
- consts: 0,
- vars: 0,
- factory: () => new ComponentWithOnDestroy(),
- template: (rf: any, ctx: any) => {},
- });
-
- ngOnDestroy() { wasOnDestroyCalled = true; }
- }
-
- // This test asserts that the view tree is set up correctly based on the knowledge that this
- // tree is used during view destruction. If the child view is not correctly attached as a
- // child of the root view, then the onDestroy hook on the child view will never be called
- // when the view tree is torn down following the destruction of that root view.
- const ComponentWithChildOnDestroy = createComponent('test-app', (rf: RenderFlags, ctx: any) => {
- if (rf & RenderFlags.Create) {
- ɵɵelement(0, 'comp-with-destroy');
- }
- }, 1, 0, [ComponentWithOnDestroy], [], null, [], []);
-
- const fixture = new ComponentFixture(ComponentWithChildOnDestroy);
- fixture.update();
-
- fixture.destroy();
- expect(wasOnDestroyCalled)
- .toBe(
- true,
- 'Expected component onDestroy method to be called when its parent view is destroyed');
- });
-
-});