Skip to content

Commit

Permalink
feat(jest-runtime): expose isTornDown variable
Browse files Browse the repository at this point in the history
This commit adds a new feature to the Jest runtime package that exposes
the `isTornDown` variable as a way to check if the Jest environment has
been torn down programmatically. The `isTornDown` variable is a
read-only boolean that is set to `true` when the environment is torn
down and `false` otherwise.

The commit also adds documentation for the `isTornDown` variable to the
Jest runtime module.

Closes jestjs#13640
  • Loading branch information
pepe authored and pepe committed Dec 28, 2022
1 parent fb2de8a commit 805534e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/jest-environment/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
1 change: 1 addition & 0 deletions packages/jest-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2225,6 +2225,7 @@ export default class Runtime {
},
getTimerCount: () => _getFakeTimers().getTimerCount(),
isMockFunction: this._moduleMocker.isMockFunction,
isTornDown: this.isTornDown,
isolateModules,
mock,
mocked,
Expand Down

0 comments on commit 805534e

Please sign in to comment.