Skip to content

Commit

Permalink
fix: Remove redundant microtask flush
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed May 22, 2023
1 parent 5dc81dc commit 7cf22ce
Showing 1 changed file with 1 addition and 29 deletions.
30 changes: 1 addition & 29 deletions src/pure.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,6 @@ import act, {
} from './act-compat'
import {fireEvent} from './fire-event'

function jestFakeTimersAreEnabled() {
/* istanbul ignore else */
if (typeof jest !== 'undefined' && jest !== null) {
return (
// legacy timers
setTimeout._isMockFunction === true || // modern timers
// eslint-disable-next-line prefer-object-has-own -- No Object.hasOwn in all target environments we support.
Object.prototype.hasOwnProperty.call(setTimeout, 'clock')
)
} // istanbul ignore next

return false
}

configureDTL({
unstable_advanceTimersWrapper: cb => {
return act(cb)
Expand All @@ -37,21 +23,7 @@ configureDTL({
const previousActEnvironment = getIsReactActEnvironment()
setReactActEnvironment(false)
try {
const result = await cb()
// Drain microtask queue.
// Otherwise we'll restore the previous act() environment, before we resolve the `waitFor` call.
// The caller would have no chance to wrap the in-flight Promises in `act()`
await new Promise(resolve => {
setTimeout(() => {
resolve()
}, 0)

if (jestFakeTimersAreEnabled()) {
jest.advanceTimersByTime(0)
}
})

return result
return await cb()
} finally {
setReactActEnvironment(previousActEnvironment)
}
Expand Down

0 comments on commit 7cf22ce

Please sign in to comment.