Skip to content

Commit 1208456

Browse files
crisbetowagnermaciel
authored andcommitted
fix(cdk/overlay): expand test environment check (#22927)
We have some logic in the overlay container that tries to prevent overlays from leaking between tests. The logic is currently limited to Jasmine tests and it happened to work by accident for Jest. Jest has made some changes that will break our check so these changes rework the logic to detect Jest and Mocha correctly. Fixes #22926. (cherry picked from commit 3f26e99)
1 parent 2e2f755 commit 1208456

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/cdk/overlay/overlay-container.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,20 @@ 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;
17+
1318
/**
1419
* Whether we're in a testing environment.
15-
* TODO(crisbeto): remove this once we have an overlay testing module.
20+
* TODO(crisbeto): remove this once we have an overlay testing module or Angular starts tearing
21+
* down the testing `NgModule` (see https://github.com/angular/angular/issues/18831).
1622
*/
17-
const isTestEnvironment: boolean = typeof window !== 'undefined' && !!window &&
18-
!!((window as any).__karma__ || (window as any).jasmine);
23+
const isTestEnvironment = (typeof __karma__ !== 'undefined' && !!__karma__) ||
24+
(typeof jasmine !== 'undefined' && !!jasmine) ||
25+
(typeof jest !== 'undefined' && !!jest) ||
26+
(typeof Mocha !== 'undefined' && !!Mocha);
1927

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

0 commit comments

Comments
 (0)