Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(material/core): avoid running sanity checks on some test environm…
…ents (#23374) Fixes that the sanity checks were running on some testing environments like Jest. These changes also move the test environment check into a centralized place so that it's easier to keep up to date. Fixes #23365. (cherry picked from commit ca67623)
- Loading branch information
1 parent
dc658be
commit 01d8e89
Showing
5 changed files
with
41 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters