Skip to content

Commit

Permalink
fix(setImmediate): make code resilient to setImmediate not existing
Browse files Browse the repository at this point in the history
  • Loading branch information
facundop3 committed Mar 25, 2021
1 parent c6acb0a commit e4d4729
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ function runWithRealTimers(callback) {

function runWithJestRealTimers(callback) {
const timerAPI = {
clearImmediate,
clearInterval,
clearTimeout,
setImmediate,
setInterval,
setTimeout,
}
if (typeof setImmediate === 'function') {
timerAPI.setImmediate = setImmediate
}
if (typeof clearImmediate === 'function') {
timerAPI.clearImmediate = clearImmediate
}

jest.useRealTimers()

Expand Down
3 changes: 1 addition & 2 deletions src/wait-for-dom-change.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
getWindowFromNode,
getDocument,
setImmediate,
setTimeout,
clearTimeout,
runWithRealTimers,
Expand Down Expand Up @@ -39,7 +38,7 @@ function waitForDomChange({

function onDone(error, result) {
clearTimeout(timer)
setImmediate(() => observer.disconnect())
setTimeout(() => observer.disconnect(), 0)
if (error) {
reject(error)
} else {
Expand Down

0 comments on commit e4d4729

Please sign in to comment.