Skip to content

Commit

Permalink
fix: Remove redundant flush of microtask queue
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Silbermann committed May 28, 2023
1 parent 4961964 commit b156f87
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 => {
// Only needed to support test environments that enable fake timers after modules are loaded.
Expand All @@ -43,21 +29,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 b156f87

Please sign in to comment.