From b5cf504443f5b679d284aad878d8ab7ef405b0b0 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Sun, 28 May 2023 11:14:38 +0200 Subject: [PATCH] fix: Remove redundant flush of microtask queue --- src/pure.js | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) diff --git a/src/pure.js b/src/pure.js index 7e25c3dd..5c1a5992 100644 --- a/src/pure.js +++ b/src/pure.js @@ -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. @@ -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) }