diff --git a/modules/component/spec/core/utils/has-zone.spec.ts b/modules/component/spec/core/utils/has-zone.spec.ts new file mode 100644 index 0000000000..ae64193786 --- /dev/null +++ b/modules/component/spec/core/utils/has-zone.spec.ts @@ -0,0 +1,42 @@ +import { hasZone } from '../../../src/core/utils/has-zone'; +import { ApplicationRef, Component, NgModule, NgZone } from '@angular/core'; +import { NoopAnimationsModule } from '@angular/platform-browser/animations'; +import { getTestBed } from '@angular/core/testing'; + +describe('hasZone', () => { + async function setup({ defaultZone }: { defaultZone: boolean }) { + @Component({ + selector: 'body', + template: '
', + }) + class NgZoneTestComponent { + checkNgZone = hasZone(this.ngZone); + constructor(readonly ngZone: NgZone) {} + } + + @NgModule({ + declarations: [NgZoneTestComponent], + exports: [NgZoneTestComponent], + bootstrap: [NgZoneTestComponent], + imports: [NoopAnimationsModule], + }) + class MyAppModule {} + + const platform = getTestBed().platform; + const moduleRef = defaultZone + ? await platform.bootstrapModule(MyAppModule) + : await platform.bootstrapModule(MyAppModule, { ngZone: 'noop' }); + const appRef = moduleRef.injector.get(ApplicationRef); + const testComp = appRef.components[0].instance; + + return { hasZone: testComp.checkNgZone }; + } + + it('returns false when default zone is used', async () => { + expect(await setup({ defaultZone: true })).toEqual({ hasZone: true }); + }); + + it('returns true when noop zone is chosen', async () => { + expect(await setup({ defaultZone: false })).toEqual({ hasZone: false }); + }); +}); diff --git a/modules/component/spec/core/utils/zone-check.spec.ts b/modules/component/spec/core/utils/zone-check.spec.ts deleted file mode 100644 index d9ed62fb73..0000000000 --- a/modules/component/spec/core/utils/zone-check.spec.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { isNgZone } from '../../../src/core/utils'; -import { - manualInstanceNgZone, - manualInstanceNoopNgZone, -} from '../../fixtures/fixtures'; - -describe('envZonePatched', () => { - it('should return true if `zone.js` did patch the global API', () => { - expect(isNgZone(manualInstanceNgZone)).toBe(true); - }); - - it('should return false if `zone.js` did not patch the global API', () => { - expect(isNgZone(manualInstanceNoopNgZone)).toBe(false); - }); -}); diff --git a/modules/component/spec/fixtures/fixtures.ts b/modules/component/spec/fixtures/fixtures.ts index eec051efd7..67814d87cf 100644 --- a/modules/component/spec/fixtures/fixtures.ts +++ b/modules/component/spec/fixtures/fixtures.ts @@ -1,13 +1,7 @@ import createSpy = jasmine.createSpy; -import { ChangeDetectorRef } from '@angular/core'; -import { MockNgZone } from './mock-ng-zone'; +import { ChangeDetectorRef, NgZone } from '@angular/core'; import { MockNoopNgZone } from './mock-noop-ng-zone'; -/** - * this is not exposed as NgZone should never be exposed to get miss matched with the real one - */ -class NgZone extends MockNgZone {} - /** * this is not exposed as NgZone should never be exposed to get miss matched with the real one */ diff --git a/modules/component/spec/fixtures/mock-ng-zone.ts b/modules/component/spec/fixtures/mock-ng-zone.ts deleted file mode 100644 index 57d1ed9b79..0000000000 --- a/modules/component/spec/fixtures/mock-ng-zone.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { MockEventEmitter } from './mock-event-emitter'; - -/** - * source: https://github.com/angular/angular/blob/master/packages/core/src/zone/ng_zone.ts#L88 - */ -export class MockNgZone { - readonly hasPendingMacrotasks: boolean = false; - readonly hasPendingMicrotasks: boolean = false; - readonly isStable: boolean = true; - readonly onUnstable: MockEventEmitter