8
8
9
9
import { DOCUMENT } from '@angular/common' ;
10
10
import { Inject , Injectable , OnDestroy } from '@angular/core' ;
11
- import { Platform } from '@angular/cdk/platform' ;
12
-
13
- // Avoid using `declare const` because it caused conflicts inside Google
14
- // with the real typings for these symbols. We use `declare interface` instead
15
- // of just `interface` for interop with Closure Compiler (prevents property renaming):
16
- // https://github.com/angular/tsickle/blob/master/README.md#differences-from-typescript
17
- declare interface TestGlobals {
18
- jasmine : unknown ;
19
- __karma__ : unknown ;
20
- jest : unknown ;
21
- Mocha : unknown ;
22
- }
23
-
24
- const globalsForTest = ( typeof window !== 'undefined' ? window : { } ) as { } as TestGlobals ;
25
-
26
- /**
27
- * Whether we're in a testing environment.
28
- * TODO(crisbeto): remove this once we have an overlay testing module or Angular starts tearing
29
- * down the testing `NgModule` (see https://github.com/angular/angular/issues/18831).
30
- */
31
- const isTestEnvironment =
32
- ( typeof globalsForTest . __karma__ !== 'undefined' && ! ! globalsForTest . __karma__ ) ||
33
- ( typeof globalsForTest . jasmine !== 'undefined' && ! ! globalsForTest . jasmine ) ||
34
- ( typeof globalsForTest . jest !== 'undefined' && ! ! globalsForTest . jest ) ||
35
- ( typeof globalsForTest . Mocha !== 'undefined' && ! ! globalsForTest . Mocha ) ;
11
+ import { Platform , _isTestEnvironment } from '@angular/cdk/platform' ;
36
12
37
13
/** Container inside which all overlays will render. */
38
14
@Injectable ( { providedIn : 'root' } )
@@ -54,7 +30,7 @@ export class OverlayContainer implements OnDestroy {
54
30
55
31
/**
56
32
* This method returns the overlay container element. It will lazily
57
- * create the element the first time it is called to facilitate using
33
+ * create the element the first time it is called to facilitate using
58
34
* the container in non-browser environments.
59
35
* @returns the container element
60
36
*/
@@ -73,7 +49,10 @@ export class OverlayContainer implements OnDestroy {
73
49
protected _createContainer ( ) : void {
74
50
const containerClass = 'cdk-overlay-container' ;
75
51
76
- if ( this . _platform . isBrowser || isTestEnvironment ) {
52
+ // TODO(crisbeto): remove the testing check once we have an overlay testing
53
+ // module or Angular starts tearing down the testing `NgModule`. See:
54
+ // https://github.com/angular/angular/issues/18831
55
+ if ( this . _platform . isBrowser || _isTestEnvironment ( ) ) {
77
56
const oppositePlatformContainers =
78
57
this . _document . querySelectorAll ( `.${ containerClass } [platform="server"], ` +
79
58
`.${ containerClass } [platform="test"]` ) ;
@@ -97,7 +76,7 @@ export class OverlayContainer implements OnDestroy {
97
76
// module which does the cleanup, we try to detect that we're in a test environment and we
98
77
// always clear the container. See #17006.
99
78
// TODO(crisbeto): remove the test environment check once we have an overlay testing module.
100
- if ( isTestEnvironment ) {
79
+ if ( _isTestEnvironment ( ) ) {
101
80
container . setAttribute ( 'platform' , 'test' ) ;
102
81
} else if ( ! this . _platform . isBrowser ) {
103
82
container . setAttribute ( 'platform' , 'server' ) ;
0 commit comments