forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_hooks.ts
More file actions
49 lines (43 loc) · 1.81 KB
/
test_hooks.ts
File metadata and controls
49 lines (43 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
/**
* Public Test Library for unit testing Angular applications. Assumes that you are running
* with Jasmine, Mocha, or a similar framework which exports a beforeEach function and
* allows tests to be asynchronous by either returning a promise or using a 'done' parameter.
*/
import {resetFakeAsyncZoneIfExists} from './fake_async';
import {TestBedImpl} from './test_bed';
// Reset the test providers and the fake async zone before each test.
// We keep a guard because somehow this file can make it into a bundle and be executed
// beforeEach is only defined when executing the tests
globalThis.beforeEach?.(getCleanupHook(false));
// We provide both a `beforeEach` and `afterEach`, because the updated behavior for
// tearing down the module is supposed to run after the test so that we can associate
// teardown errors with the correct test.
// We keep a guard because somehow this file can make it into a bundle and be executed
// afterEach is only defined when executing the tests
globalThis.afterEach?.(getCleanupHook(true));
function getCleanupHook(expectedTeardownValue: boolean) {
return () => {
const testBed = TestBedImpl.INSTANCE;
if (testBed.shouldTearDownTestingModule() === expectedTeardownValue) {
testBed.resetTestingModule();
resetFakeAsyncZoneIfExists();
}
};
}
/**
* This API should be removed. But doing so seems to break `google3` and so it requires a bit of
* investigation.
*
* A work around is to mark it as `@codeGenApi` for now and investigate later.
*
* @codeGenApi
*/
// TODO(iminar): Remove this code in a safe way.
export const __core_private_testing_placeholder__ = '';