-
Notifications
You must be signed in to change notification settings - Fork 470
test: enable modern jest timers test #938
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't @timdeschryver I think this is fixed by #966 and #962 without needing to change these particular tests. Can we close this PR in favor of #962? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes of course. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It could've been a bug in |
||
} | ||
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() | ||
}) | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.