-
Notifications
You must be signed in to change notification settings - Fork 6.7k
/
test-environment.ts
28 lines (25 loc) · 1.15 KB
/
test-environment.ts
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
/**
* @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.io/license
*/
// Avoid using `declare const` because it caused conflicts inside Google
// with the real typings for these symbols. We use `declare interface` instead
// of just `interface` for interop with Closure Compiler (prevents property renaming):
// https://github.com/angular/tsickle/blob/master/README.md#differences-from-typescript
declare interface TestGlobals {
jasmine: unknown;
__karma__: unknown;
jest: unknown;
Mocha: unknown;
}
const testGlobals = (typeof window !== 'undefined' ? window : {}) as {} as TestGlobals;
/** Gets whether the code is currently running in a test environment. */
export function _isTestEnvironment(): boolean {
return (typeof testGlobals.__karma__ !== 'undefined' && !!testGlobals.__karma__) ||
(typeof testGlobals.jasmine !== 'undefined' && !!testGlobals.jasmine) ||
(typeof testGlobals.jest !== 'undefined' && !!testGlobals.jest) ||
(typeof testGlobals.Mocha !== 'undefined' && !!testGlobals.Mocha);
}