Skip to content

Commit

Permalink
fix(runtime): handle missing replaceProperty (#13823)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Jan 26, 2023
1 parent c78905c commit fbf0fa8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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

Expand Down
11 changes: 8 additions & 3 deletions packages/jest-runtime/src/index.ts
Expand Up @@ -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;
Expand Down

0 comments on commit fbf0fa8

Please sign in to comment.