|
7 | 7 | */ |
8 | 8 |
|
9 | 9 | import {PLATFORM_BROWSER_ID, PLATFORM_SERVER_ID} from '@angular/common/src/platform_id'; |
10 | | -import {afterNextRender, afterRender, AfterRenderRef, ChangeDetectorRef, Component, inject, Injector, PLATFORM_ID, ViewContainerRef} from '@angular/core'; |
| 10 | +import {afterNextRender, afterRender, AfterRenderRef, ChangeDetectorRef, Component, inject, Injector, NgZone, PLATFORM_ID, ViewContainerRef} from '@angular/core'; |
11 | 11 | import {TestBed} from '@angular/core/testing'; |
12 | 12 |
|
13 | 13 | describe('after render hooks', () => { |
@@ -225,6 +225,29 @@ describe('after render hooks', () => { |
225 | 225 | expect(outerHookCount).toBe(3); |
226 | 226 | expect(innerHookCount).toBe(2); |
227 | 227 | }); |
| 228 | + |
| 229 | + it('should run outside of the Angular zone', () => { |
| 230 | + const zoneLog: boolean[] = []; |
| 231 | + |
| 232 | + @Component({selector: 'comp'}) |
| 233 | + class Comp { |
| 234 | + constructor() { |
| 235 | + afterRender(() => { |
| 236 | + zoneLog.push(NgZone.isInAngularZone()); |
| 237 | + }); |
| 238 | + } |
| 239 | + } |
| 240 | + |
| 241 | + TestBed.configureTestingModule({ |
| 242 | + declarations: [Comp], |
| 243 | + ...COMMON_CONFIGURATION, |
| 244 | + }); |
| 245 | + const fixture = TestBed.createComponent(Comp); |
| 246 | + |
| 247 | + expect(zoneLog).toEqual([]); |
| 248 | + fixture.detectChanges(); |
| 249 | + expect(zoneLog).toEqual([false]); |
| 250 | + }); |
228 | 251 | }); |
229 | 252 |
|
230 | 253 | describe('afterNextRender', () => { |
@@ -431,6 +454,29 @@ describe('after render hooks', () => { |
431 | 454 | expect(outerHookCount).toBe(1); |
432 | 455 | expect(innerHookCount).toBe(1); |
433 | 456 | }); |
| 457 | + |
| 458 | + it('should run outside of the Angular zone', () => { |
| 459 | + const zoneLog: boolean[] = []; |
| 460 | + |
| 461 | + @Component({selector: 'comp'}) |
| 462 | + class Comp { |
| 463 | + constructor() { |
| 464 | + afterNextRender(() => { |
| 465 | + zoneLog.push(NgZone.isInAngularZone()); |
| 466 | + }); |
| 467 | + } |
| 468 | + } |
| 469 | + |
| 470 | + TestBed.configureTestingModule({ |
| 471 | + declarations: [Comp], |
| 472 | + ...COMMON_CONFIGURATION, |
| 473 | + }); |
| 474 | + const fixture = TestBed.createComponent(Comp); |
| 475 | + |
| 476 | + expect(zoneLog).toEqual([]); |
| 477 | + fixture.detectChanges(); |
| 478 | + expect(zoneLog).toEqual([false]); |
| 479 | + }); |
434 | 480 | }); |
435 | 481 | }); |
436 | 482 |
|
|
0 commit comments