Skip to content

Commit

Permalink
fix(cdk/overlay): expand test environment check (#22927)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
crisbeto authored and wagnermaciel committed Jun 10, 2021
1 parent 2e2f755 commit 1208456
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/cdk/overlay/overlay-container.ts
Expand Up @@ -10,12 +10,20 @@ import {DOCUMENT} from '@angular/common';
import {Inject, Injectable, OnDestroy} from '@angular/core';
import {Platform} from '@angular/cdk/platform';

declare const __karma__: unknown;
declare const jasmine: unknown;
declare const jest: unknown;
declare const Mocha: unknown;

/**
* Whether we're in a testing environment.
* TODO(crisbeto): remove this once we have an overlay testing module.
* TODO(crisbeto): remove this once we have an overlay testing module or Angular starts tearing
* down the testing `NgModule` (see https://github.com/angular/angular/issues/18831).
*/
const isTestEnvironment: boolean = typeof window !== 'undefined' && !!window &&
!!((window as any).__karma__ || (window as any).jasmine);
const isTestEnvironment = (typeof __karma__ !== 'undefined' && !!__karma__) ||
(typeof jasmine !== 'undefined' && !!jasmine) ||
(typeof jest !== 'undefined' && !!jest) ||
(typeof Mocha !== 'undefined' && !!Mocha);

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

0 comments on commit 1208456

Please sign in to comment.