|
7 | 7 | */
|
8 | 8 | import {animate, AnimationPlayer, AnimationTriggerMetadata, state, style, transition, trigger} from '@angular/animations';
|
9 | 9 | import {ɵAnimationEngine as AnimationEngine} from '@angular/animations/browser';
|
10 |
| -import {Component, Injectable, NgZone, RendererFactory2, RendererType2, ViewChild} from '@angular/core'; |
| 10 | +import {Component, destroyPlatform, Injectable, NgModule, NgZone, RendererFactory2, RendererType2, ViewChild} from '@angular/core'; |
11 | 11 | import {TestBed} from '@angular/core/testing';
|
| 12 | +import {platformBrowserDynamic} from '@angular/platform-browser-dynamic'; |
12 | 13 | import {BrowserAnimationsModule, ɵAnimationRendererFactory as AnimationRendererFactory, ɵInjectableAnimationEngine as InjectableAnimationEngine} from '@angular/platform-browser/animations';
|
13 | 14 | import {DomRendererFactory2} from '@angular/platform-browser/src/dom/dom_renderer';
|
| 15 | +import {onlyInIvy, withBody} from '@angular/private/testing'; |
14 | 16 |
|
15 | 17 | import {el} from '../../testing/src/browser_util';
|
16 | 18 |
|
@@ -323,6 +325,37 @@ describe('AnimationRendererFactory', () => {
|
323 | 325 | expect(renderer.log).toEqual(['begin', 'end']);
|
324 | 326 | });
|
325 | 327 | });
|
| 328 | + |
| 329 | +onlyInIvy('View Engine uses another mechanism of removing DOM nodes').describe('destroy', () => { |
| 330 | + beforeEach(destroyPlatform); |
| 331 | + afterEach(destroyPlatform); |
| 332 | + |
| 333 | + it('should clear bootstrapped component contents', |
| 334 | + withBody('<div>before</div><app-root></app-root><div>after</div>', async () => { |
| 335 | + @Component({selector: 'app-root', template: 'app-root content'}) |
| 336 | + class AppComponent { |
| 337 | + } |
| 338 | + |
| 339 | + @NgModule({ |
| 340 | + imports: [BrowserAnimationsModule], |
| 341 | + declarations: [AppComponent], |
| 342 | + bootstrap: [AppComponent] |
| 343 | + }) |
| 344 | + class AppModule { |
| 345 | + } |
| 346 | + |
| 347 | + const ngModuleRef = await platformBrowserDynamic().bootstrapModule(AppModule); |
| 348 | + |
| 349 | + const root = document.body.querySelector('app-root')!; |
| 350 | + expect(root.textContent).toEqual('app-root content'); |
| 351 | + expect(document.body.childNodes.length).toEqual(3); |
| 352 | + |
| 353 | + ngModuleRef.destroy(); |
| 354 | + |
| 355 | + expect(document.body.querySelector('app-root')).toBeFalsy(); // host element is removed |
| 356 | + expect(document.body.childNodes.length).toEqual(2); // other elements are preserved |
| 357 | + })); |
| 358 | +}); |
326 | 359 | })();
|
327 | 360 |
|
328 | 361 | @Injectable()
|
|
0 commit comments