Skip to content

Commit

Permalink
fix(legacy-timers): Do not add setImmediate and clearImmediate if…
Browse files Browse the repository at this point in the history
… they do not exist in the global environment (#11599)
  • Loading branch information
SimenB authored Jun 22, 2021
1 parent e5f9f21 commit 6373529
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 6373529

Please sign in to comment.