fix(fakeAsync): have fakeAsync use Proxy zone. (#10797)
Closes #10503 It is possible for code in `beforeEach` to capture and fork a zone (for example creating `NgZone` in `beforeEach`). Subsequently the code in `it` may chose to do `fakeAsync`. The issue is that because the code in `it` can use `NgZone` from the `beforeEach`. it effectively can escape the `fakeAsync` zone. A solution is to run all of the test in `ProxyZone` which allows a test to dynamically replace the rules at any time. This allows the `beforeEach` to fork a zone, and then `it` to retroactively became `fakeAsync` zone.
This commit is contained in:
@ -34,7 +34,7 @@ var jsmIt = _global.it;
|
||||
var jsmIIt = _global.fit;
|
||||
var jsmXIt = _global.xit;
|
||||
|
||||
var runnerStack: any[] /** TODO #9100 */ = [];
|
||||
var runnerStack: BeforeEachRunner[] = [];
|
||||
var inIt = false;
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 3000;
|
||||
var globalTimeOut = jasmine.DEFAULT_TIMEOUT_INTERVAL;
|
||||
@ -62,7 +62,7 @@ class BeforeEachRunner {
|
||||
// Reset the test providers before each test
|
||||
jsmBeforeEach(() => { testBed.resetTestingModule(); });
|
||||
|
||||
function _describe(jsmFn: any /** TODO #9100 */, ...args: any[] /** TODO #9100 */) {
|
||||
function _describe(jsmFn: Function, ...args: any[]) {
|
||||
var parentRunner = runnerStack.length === 0 ? null : runnerStack[runnerStack.length - 1];
|
||||
var runner = new BeforeEachRunner(parentRunner);
|
||||
runnerStack.push(runner);
|
||||
@ -71,15 +71,15 @@ function _describe(jsmFn: any /** TODO #9100 */, ...args: any[] /** TODO #9100 *
|
||||
return suite;
|
||||
}
|
||||
|
||||
export function describe(...args: any[] /** TODO #9100 */): void {
|
||||
export function describe(...args: any[]): void {
|
||||
return _describe(jsmDescribe, ...args);
|
||||
}
|
||||
|
||||
export function ddescribe(...args: any[] /** TODO #9100 */): void {
|
||||
export function ddescribe(...args: any[]): void {
|
||||
return _describe(jsmDDescribe, ...args);
|
||||
}
|
||||
|
||||
export function xdescribe(...args: any[] /** TODO #9100 */): void {
|
||||
export function xdescribe(...args: any[]): void {
|
||||
return _describe(jsmXDescribe, ...args);
|
||||
}
|
||||
|
||||
@ -105,7 +105,7 @@ export function beforeEach(fn: Function): void {
|
||||
* {provide: SomeToken, useValue: myValue},
|
||||
* ]);
|
||||
*/
|
||||
export function beforeEachProviders(fn: any /** TODO #9100 */): void {
|
||||
export function beforeEachProviders(fn: Function): void {
|
||||
jsmBeforeEach(() => {
|
||||
var providers = fn();
|
||||
if (!providers) return;
|
||||
@ -128,7 +128,7 @@ export function addProviders(providers: Array<any>): void {
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
export function beforeEachBindings(fn: any /** TODO #9100 */): void {
|
||||
export function beforeEachBindings(fn: Function): void {
|
||||
beforeEachProviders(fn);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user