Skip to content

Commit 914e453

Browse files
committed
fix(core): test cleanup should not throw if Zone is not present (#55096)
The test hooks should not throw if applications choose not to load ZoneJS. fixes #48198 PR Close #55096
1 parent a48afe0 commit 914e453

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

packages/core/testing/src/fake_async.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ export function resetFakeAsyncZone(): void {
2525
throw new Error(fakeAsyncTestModuleNotLoadedErrorMessage);
2626
}
2727

28+
export function resetFakeAsyncZoneIfExists(): void {
29+
if (fakeAsyncTestModule) {
30+
fakeAsyncTestModule.resetFakeAsyncZone();
31+
}
32+
}
33+
2834
/**
2935
* Wraps a function to be executed in the `fakeAsync` zone:
3036
* - Microtasks are manually executed by calling `flushMicrotasks()`.

packages/core/testing/src/test_hooks.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* allows tests to be asynchronous by either returning a promise or using a 'done' parameter.
1313
*/
1414

15-
import {resetFakeAsyncZone} from './fake_async';
15+
import {resetFakeAsyncZoneIfExists} from './fake_async';
1616
import {TestBedImpl} from './test_bed';
1717

1818
// Reset the test providers and the fake async zone before each test.
@@ -32,7 +32,7 @@ function getCleanupHook(expectedTeardownValue: boolean) {
3232
const testBed = TestBedImpl.INSTANCE;
3333
if (testBed.shouldTearDownTestingModule() === expectedTeardownValue) {
3434
testBed.resetTestingModule();
35-
resetFakeAsyncZone();
35+
resetFakeAsyncZoneIfExists();
3636
}
3737
};
3838
}

packages/core/testing/src/testing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
export * from './async';
1616
export {ComponentFixture} from './component_fixture';
17-
export * from './fake_async';
17+
export {resetFakeAsyncZone, discardPeriodicTasks, fakeAsync, flush, flushMicrotasks, tick} from './fake_async';
1818
export {TestBed, getTestBed, TestBedStatic, inject, InjectSetupWrapper, withModule} from './test_bed';
1919
export {TestComponentRenderer, ComponentFixtureAutoDetect, ComponentFixtureNoNgZone, TestModuleMetadata, TestEnvironmentOptions, ModuleTeardownOptions} from './test_bed_common';
2020
export * from './test_hooks';

0 commit comments

Comments
 (0)