Skip to content

Commit 10a1ac7

Browse files
author
Sebastian Silbermann
committed
robuster assertion for not calling callback again
1 parent ce11c0f commit 10a1ac7

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

src/__tests__/wait-for.js

+10-15
Original file line numberDiff line numberDiff line change
@@ -431,24 +431,19 @@ test(`when fake timer is installed, on waitFor timeout, it doesn't call the call
431431
},
432432
})
433433

434-
let waitForHasResolved = false
435-
let callbackCalledAfterWaitForResolved = false
434+
const callback = jest.fn(() => {
435+
throw new Error('We want to timeout')
436+
})
437+
const interval = 50
436438

437439
await expect(() =>
438-
waitFor(
439-
() => {
440-
// eslint-disable-next-line jest/no-conditional-in-test -- false-positive
441-
if (waitForHasResolved) {
442-
callbackCalledAfterWaitForResolved = true
443-
}
444-
throw new Error('We want to timeout')
445-
},
446-
{interval: 50, timeout: 100},
447-
),
440+
waitFor(callback, {interval, timeout: 100}),
448441
).rejects.toThrow()
449-
waitForHasResolved = true
442+
expect(callback).toHaveBeenCalledWith()
450443

451-
await Promise.resolve()
444+
callback.mockClear()
445+
446+
await jest.advanceTimersByTimeAsync(interval)
452447

453-
expect(callbackCalledAfterWaitForResolved).toBe(false)
448+
expect(callback).not.toHaveBeenCalledWith()
454449
})

0 commit comments

Comments
 (0)