Skip to content

Commit aa1309c

Browse files
committed
fix: safe check for setImmediate and clearImmediate
Jest is planning to sandbox setImmediate, and this would not work since setImmediate and clearImmediate would be undefined.
1 parent c6acb0a commit aa1309c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/helpers.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,19 @@ function runWithRealTimers(callback) {
1616

1717
function runWithJestRealTimers(callback) {
1818
const timerAPI = {
19-
clearImmediate,
2019
clearInterval,
2120
clearTimeout,
22-
setImmediate,
2321
setInterval,
2422
setTimeout,
2523
}
2624

25+
if (typeof setImmediate === 'function') {
26+
timerAPI.setImmediate = setImmediate
27+
}
28+
if (typeof clearImmediate === 'function') {
29+
timerAPI.clearImmediate = clearImmediate
30+
}
31+
2732
jest.useRealTimers()
2833

2934
const callbackReturnValue = callback()

0 commit comments

Comments
 (0)