feat(testing): Use NgZone in TestComponentBuilder.
Instantiating the test component within an NgZone will let us track async tasks in event handlers and change detection. We can also do auto change detection when triggering events through dispatchEvent and not have to do fixture.detectChange() manually in the test. New API: ComponentFixture.autoDetectChanges() - This puts the fixture in auto detect mode that automatically calls detectChanges when the microtask queue is empty (Similar to how change detection is triggered in an actual application). ComponentFixture.isStable() - This returns a boolean whether the fixture is currently stable or has some async tasks that need to be completed. ComponentFixture.whenStable() - This returns a promise that is resolved when the fixture is stable after all async tasks are complete. Closes #8301
This commit is contained in:

committed by
vikerman

parent
ac55e1e27b
commit
769835e53e
@ -157,7 +157,7 @@ export class InjectSetupWrapper {
|
||||
inject(tokens: any[], fn: Function): Function {
|
||||
return () => {
|
||||
this._addProviders();
|
||||
return inject(tokens, fn)();
|
||||
return inject_impl(tokens, fn)();
|
||||
}
|
||||
}
|
||||
|
||||
@ -165,7 +165,7 @@ export class InjectSetupWrapper {
|
||||
injectAsync(tokens: any[], fn: Function): Function {
|
||||
return () => {
|
||||
this._addProviders();
|
||||
return injectAsync(tokens, fn)();
|
||||
return injectAsync_impl(tokens, fn)();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -197,3 +197,8 @@ export function withProviders(providers: () => any) {
|
||||
export function injectAsync(tokens: any[], fn: Function): Function {
|
||||
return async(inject(tokens, fn));
|
||||
}
|
||||
|
||||
// This is to ensure inject(Async) within InjectSetupWrapper doesn't call itself
|
||||
// when transpiled to Dart.
|
||||
var inject_impl = inject;
|
||||
var injectAsync_impl = injectAsync;
|
||||
|
Reference in New Issue
Block a user