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
  • Loading branch information
SimenB committed Jun 22, 2021
1 parent 6826764 commit 91c932c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
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

0 comments on commit 91c932c

Please sign in to comment.