Skip to content

Commit 3108e5b

Browse files
committed
fix: Don't assume micked timers imply jest fake timers
1 parent a25149d commit 3108e5b

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/helpers.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ function _runWithRealTimers(callback) {
2525

2626
const callbackReturnValue = callback()
2727

28-
const usedJestFakeTimers = Object.entries(timerAPI).some(
29-
([name, func]) => func !== globalObj[name],
30-
)
28+
const usedJestFakeTimers =
29+
typeof jest !== 'undefined' &&
30+
Object.entries(timerAPI).some(([name, func]) => func !== globalObj[name])
3131

3232
if (usedJestFakeTimers) {
3333
jest.useFakeTimers(timerAPI.setTimeout?.clock ? 'modern' : 'legacy')

src/wait-for.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ function waitFor(
5252

5353
const overallTimeoutTimer = setTimeout(handleTimeout, timeout)
5454

55-
const usingFakeTimers = jestFakeTimersAreEnabled()
56-
if (usingFakeTimers) {
55+
const usingJestFakeTimers = jestFakeTimersAreEnabled()
56+
if (usingJestFakeTimers) {
5757
checkCallback()
5858
// this is a dangerous rule to disable because it could lead to an
5959
// infinite loop. However, eslint isn't smart enough to know that we're
@@ -107,7 +107,7 @@ function waitFor(
107107
finished = true
108108
clearTimeout(overallTimeoutTimer)
109109

110-
if (!usingFakeTimers) {
110+
if (!usingJestFakeTimers) {
111111
clearInterval(intervalId)
112112
observer.disconnect()
113113
}

0 commit comments

Comments
 (0)