From 51fd8e74d61e361b36b94e8ba685921034aa43fb Mon Sep 17 00:00:00 2001 From: timdeschryver <28659384+timdeschryver@users.noreply.github.com> Date: Fri, 30 Apr 2021 20:13:55 +0200 Subject: [PATCH] test: enable modern timers test --- src/__tests__/fake-timers.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/__tests__/fake-timers.js b/src/__tests__/fake-timers.js index af2a09ac..92cd4f98 100644 --- a/src/__tests__/fake-timers.js +++ b/src/__tests__/fake-timers.js @@ -1,20 +1,26 @@ import {waitFor, waitForElementToBeRemoved} from '..' import {render} from './helpers/test-utils' -async function runWaitFor({time = 300} = {}, options) { +async function runWaitFor({time = 300, advanceTimers = true} = {}, options) { const response = 'data' const doAsyncThing = () => new Promise(r => setTimeout(() => r(response), time)) let result doAsyncThing().then(r => (result = r)) - + if (advanceTimers) { + jest.advanceTimersByTime(time) + } await waitFor(() => expect(result).toBe(response), options) } +afterEach(() => { + jest.useRealTimers() +}) + test('real timers', async () => { // the only difference when not using fake timers is this test will // have to wait the full length of the timeout - await runWaitFor() + await runWaitFor({advanceTimers: false}) }) test('legacy', async () => { @@ -23,7 +29,7 @@ test('legacy', async () => { }) test('modern', async () => { - jest.useFakeTimers() + jest.useFakeTimers('modern') await runWaitFor() })