diff --git a/CHANGELOG.md b/CHANGELOG.md index fc857b12fcd7..eccb30f33648 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ ### Fixes - `[@jest/expect-utils]` `toMatchObject` diffs should include `Symbol` properties ([#13810](https://github.com/facebook/jest/pull/13810)) +- `[jest-runtime]` Handle missing `replaceProperty` ([#13823](https://github.com/facebook/jest/pull/13823)) ### Chore & Maintenance diff --git a/packages/jest-runtime/src/index.ts b/packages/jest-runtime/src/index.ts index ae0f8bde2ca9..f050d0d01e58 100644 --- a/packages/jest-runtime/src/index.ts +++ b/packages/jest-runtime/src/index.ts @@ -2319,9 +2319,14 @@ export default class Runtime { 'Your test environment does not support `mocked`, please update it.', ); }); - const replaceProperty = this._moduleMocker.replaceProperty.bind( - this._moduleMocker, - ); + const replaceProperty = + typeof this._moduleMocker.replaceProperty === 'function' + ? this._moduleMocker.replaceProperty.bind(this._moduleMocker) + : () => { + throw new Error( + 'Your test environment does not support `jest.replaceProperty` - please ensure its Jest dependencies are updated to version 29.4 or later', + ); + }; const setTimeout = (timeout: number) => { this._environment.global[testTimeoutSymbol] = timeout;