forked from ngrx/platform
-
Notifications
You must be signed in to change notification settings - Fork 1
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 (ngrx#2547)
- Loading branch information
1 parent
303b8aa
commit 458204c
Showing
7 changed files
with
45 additions
and
100 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
Empty file.
This file was deleted.
Oops, something went wrong.