diff --git a/packages/jest-environment/src/index.ts b/packages/jest-environment/src/index.ts index df50111e37f5..f871458b8a49 100644 --- a/packages/jest-environment/src/index.ts +++ b/packages/jest-environment/src/index.ts @@ -172,6 +172,15 @@ export interface Jest { * local module state doesn't conflict between tests. */ isolateModules(fn: () => void): Jest; + /** + * A flag that indicates whether the Jest environment has been torn down. + * @example + * if (jest.isTornDown) { + * // The Jest environment has been torn down, so stop doing work + * return; + * } + */ + isTornDown: boolean; /** * Mocks a module with an auto-mocked version when it is being required. */ diff --git a/packages/jest-runtime/src/index.ts b/packages/jest-runtime/src/index.ts index c278d77052c5..d001c7f64438 100644 --- a/packages/jest-runtime/src/index.ts +++ b/packages/jest-runtime/src/index.ts @@ -2225,6 +2225,7 @@ export default class Runtime { }, getTimerCount: () => _getFakeTimers().getTimerCount(), isMockFunction: this._moduleMocker.isMockFunction, + isTornDown: this.isTornDown, isolateModules, mock, mocked,