hack to fix console noise from unfaked timers and clearAllModals (#10660)

pull/28788/head^2
Kerry 2023-04-21 10:35:44 +12:00 committed by GitHub
parent 5445ee85cd
commit 7a914e73f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 1 deletions

View File

@ -211,6 +211,17 @@ export const clearAllModals = async (): Promise<void> => {
// of removing the same modal because the promises don't flush otherwise. // of removing the same modal because the promises don't flush otherwise.
// //
// XXX: Maybe in the future with Jest 29.5.0+, we could use `runAllTimersAsync` instead. // XXX: Maybe in the future with Jest 29.5.0+, we could use `runAllTimersAsync` instead.
await flushPromisesWithFakeTimers();
// this is called in some places where timers are not faked
// which causes a lot of noise in the console
// to make a hack even hackier check if timers are faked using a weird trick from github
// then call the appropriate promise flusher
// https://github.com/facebook/jest/issues/10555#issuecomment-1136466942
const jestTimersFaked = setTimeout.name === "setTimeout";
if (jestTimersFaked) {
await flushPromisesWithFakeTimers();
} else {
await flushPromises();
}
} }
}; };