Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(legacy-timers): Do not add setImmediate and clearImmediate if they do not exist in the global environment #11599

Merged
merged 1 commit into from Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Expand Up @@ -7,9 +7,10 @@

### Fixes

- `[jest-fake-timers]` Do not add `setImmediate` and `clearImmediate` if they do not exist in the global environment ([#11599](https://github.com/facebook/jest/pull/11599))
- `[jest-core]` Support special characters like `@`, `+` and `()` on Windows with `--findRelatedTests` ([#11548](https://github.com/facebook/jest/pull/11548))
- `[jest-reporter]` Allow `node-notifier@10` as peer dependency ([#11523](https://github.com/facebook/jest/pull/11523))
- `[jest-reporter]` Update `v8-to-istanbul` ([#11523](https://github.com/facebook/jest/pull/11523))
- `[jest-core]` Support special characters like `@`, `+` and `()` on windows with `--findRelatedTests` ([#11548](https://github.com/facebook/jest/pull/11548))

### Chore & Maintenance

Expand Down
16 changes: 12 additions & 4 deletions packages/jest-fake-timers/src/legacyFakeTimers.ts
Expand Up @@ -334,7 +334,9 @@ export default class FakeTimers<TimerRef> {
this._timerAPIs.cancelAnimationFrame,
);
}
setGlobal(global, 'clearImmediate', this._timerAPIs.clearImmediate);
if (typeof global.clearImmediate === 'function') {
setGlobal(global, 'clearImmediate', this._timerAPIs.clearImmediate);
}
setGlobal(global, 'clearInterval', this._timerAPIs.clearInterval);
setGlobal(global, 'clearTimeout', this._timerAPIs.clearTimeout);
if (typeof global.requestAnimationFrame === 'function') {
Expand All @@ -344,7 +346,9 @@ export default class FakeTimers<TimerRef> {
this._timerAPIs.requestAnimationFrame,
);
}
setGlobal(global, 'setImmediate', this._timerAPIs.setImmediate);
if (typeof global.setImmediate === 'function') {
setGlobal(global, 'setImmediate', this._timerAPIs.setImmediate);
}
setGlobal(global, 'setInterval', this._timerAPIs.setInterval);
setGlobal(global, 'setTimeout', this._timerAPIs.setTimeout);

Expand All @@ -362,7 +366,9 @@ export default class FakeTimers<TimerRef> {
this._fakeTimerAPIs.cancelAnimationFrame,
);
}
setGlobal(global, 'clearImmediate', this._fakeTimerAPIs.clearImmediate);
if (typeof global.clearImmediate === 'function') {
setGlobal(global, 'clearImmediate', this._fakeTimerAPIs.clearImmediate);
}
setGlobal(global, 'clearInterval', this._fakeTimerAPIs.clearInterval);
setGlobal(global, 'clearTimeout', this._fakeTimerAPIs.clearTimeout);
if (typeof global.requestAnimationFrame === 'function') {
Expand All @@ -372,7 +378,9 @@ export default class FakeTimers<TimerRef> {
this._fakeTimerAPIs.requestAnimationFrame,
);
}
setGlobal(global, 'setImmediate', this._fakeTimerAPIs.setImmediate);
if (typeof global.setImmediate === 'function') {
setGlobal(global, 'setImmediate', this._fakeTimerAPIs.setImmediate);
}
setGlobal(global, 'setInterval', this._fakeTimerAPIs.setInterval);
setGlobal(global, 'setTimeout', this._fakeTimerAPIs.setTimeout);

Expand Down