Skip to content

Commit 296d115

Browse files
committed
fix(cdk/overlay): use interface for test environment globals
The previous approach of using `declare const` was causing collisions with the real test environment types inside Google.
1 parent 4caf039 commit 296d115

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/cdk/overlay/overlay-container.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,27 @@ import {DOCUMENT} from '@angular/common';
1010
import {Inject, Injectable, OnDestroy} from '@angular/core';
1111
import {Platform} from '@angular/cdk/platform';
1212

13-
declare const __karma__: unknown;
14-
declare const jasmine: unknown;
15-
declare const jest: unknown;
16-
declare const Mocha: unknown;
13+
// Avoid using `declare const` because it caused conflicts inside Google
14+
// with the real typings for these symbols.
15+
declare interface TestGlobals {
16+
jasmine: unknown;
17+
__karma__: unknown;
18+
jest: unknown;
19+
Mocha: unknown;
20+
}
21+
22+
const globalsForTest = window as {} as TestGlobals;
1723

1824
/**
1925
* Whether we're in a testing environment.
2026
* TODO(crisbeto): remove this once we have an overlay testing module or Angular starts tearing
2127
* down the testing `NgModule` (see https://github.com/angular/angular/issues/18831).
2228
*/
23-
const isTestEnvironment = (typeof __karma__ !== 'undefined' && !!__karma__) ||
24-
(typeof jasmine !== 'undefined' && !!jasmine) ||
25-
(typeof jest !== 'undefined' && !!jest) ||
26-
(typeof Mocha !== 'undefined' && !!Mocha);
29+
const isTestEnvironment =
30+
(typeof globalsForTest.__karma__ !== 'undefined' && !!globalsForTest.__karma__) ||
31+
(typeof globalsForTest.jasmine !== 'undefined' && !!globalsForTest.jasmine) ||
32+
(typeof globalsForTest.jest !== 'undefined' && !!globalsForTest.jest) ||
33+
(typeof globalsForTest.Mocha !== 'undefined' && !!globalsForTest.Mocha);
2734

2835
/** Container inside which all overlays will render. */
2936
@Injectable({providedIn: 'root'})

0 commit comments

Comments
 (0)