mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
test: Add flushPromises utility function
This commit is contained in:
@@ -44,6 +44,17 @@ export function describeIf(envFlag: string, name: string, fn: () => void): void
|
||||
return enabled ? describe(name, fn) : describe.skip(name, fn);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is needed when you want to wait for all promises to resolve.
|
||||
* Also works when using jest.useFakeTimers().
|
||||
* For more details see the links below
|
||||
* - https://github.com/facebook/jest/issues/2157
|
||||
* - https://stackoverflow.com/questions/52177631/jest-timer-and-promise-dont-work-well-settimeout-and-async-function
|
||||
*/
|
||||
export async function flushPromises(): Promise<void> {
|
||||
return new Promise(jest.requireActual('timers').setImmediate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mocks (some) functions of the fs system library.
|
||||
* It is important that you call `jest.mock('fs');` in your test file before calling this!!!
|
||||
|
||||
Reference in New Issue
Block a user