-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(component): detect zone.js using instanceof comparison (#2547)
- Loading branch information
1 parent
ba0818e
commit 7128667
Showing
8 changed files
with
47 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: '<div></div>', | ||
}) | ||
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 }); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export * from './get-global-this'; | ||
export * from './zone-checks'; | ||
export * from './has-zone'; | ||
export * from './is-ivy'; |
This file was deleted.
Oops, something went wrong.