Repository navigation
fix: Support older test environments whose moduleMocker does not implement clearMocksOnScope - #16169
Conversation
✅ Deploy Preview for jestjs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
babel-jest
babel-plugin-jest-hoist
babel-preset-jest
create-jest
@jest/diff-sequences
expect
@jest/expect-utils
jest
jest-changed-files
jest-circus
jest-cli
jest-config
@jest/console
@jest/core
@jest/create-cache-key-function
jest-diff
jest-docblock
jest-each
@jest/environment
jest-environment-jsdom
@jest/environment-jsdom-abstract
jest-environment-node
@jest/expect
@jest/fake-timers
@jest/get-type
@jest/globals
jest-haste-map
jest-jasmine2
jest-leak-detector
jest-matcher-utils
jest-message-util
jest-mock
@jest/pattern
jest-phabricator
jest-regex-util
@jest/reporters
jest-resolve
jest-resolve-dependencies
jest-runner
jest-runtime
@jest/schemas
jest-snapshot
@jest/snapshot-utils
@jest/source-map
@jest/test-result
@jest/test-sequencer
@jest/transform
@jest/types
jest-util
jest-validate
jest-watcher
jest-worker
pretty-format
commit: |
| '`moduleMocker` must be set on an environment when created', | ||
| ); | ||
| this._moduleMocker = this._environment.moduleMocker; | ||
| if (typeof this._moduleMocker.clearMocksOnScope !== 'function') { |
There was a problem hiding this comment.
I don't think we should explode here. We should just skip the clearMocksOnScope call
diff --git i/packages/jest-runtime/src/index.ts w/packages/jest-runtime/src/index.ts
index e85d58ed01..a67a073966 100644
--- i/packages/jest-runtime/src/index.ts
+++ w/packages/jest-runtime/src/index.ts
@@ -555,7 +555,7 @@ export default class Runtime {
if (this._environment) {
if (this._environment.global) {
- this._moduleMocker.clearMocksOnScope(this._environment.global);
+ this._moduleMocker.clearMocksOnScope?.(this._environment.global);
}
if (this._environment.fakeTimers) {it's a nice extra feature, but not require at all for the runtime to function
There was a problem hiding this comment.
Ah right. I didn't have enough context knowledge to know that this thing is not actually required. I think there are other cases that basically die on the same thing (not sure though) - so I'll make sure to make this optional in every case and revert the error message.
There was a problem hiding this comment.
In the end your change request was enough and there was no other case :)
moduleMocker does not implement clearMocksOnScope
|
Hi! When version with this fix will be published? Faced same issue |
jest 30.4.0 introduced clearMocksOnScope(), but did not deal properly with environments missing that method. The react-native jest environment seems to be missing it, causing the unit tests to fail. This is fixed by [jest#16169](jestjs/jest#16169) but has not been released yet. Once merged, the range can be `^30.4.0`.
jest 30.4.0 introduced clearMocksOnScope(), but did not deal properly with environments missing that method. The react-native jest environment seems to be missing it, causing the unit tests to fail. This is fixed by [jest#16169](jestjs/jest#16169) but has not been released yet. Once merged, the range can be `^30.4.0`.
Can be restored once jestjs/jest#16169 is released
Can be restored once jestjs/jest#16169 is released
Can be restored once jestjs/jest#16169 is released
Can be restored once jestjs/jest#16169 is released
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
Provides more descriptive error message so, that people trying to use new Jest will not spend too much time trying to figure out what went wrong.
Covers issue #16168
Test plan
I added tests covering the functionality.