jest wait code example
Example 1: jest wait for x seconds
jest.setTimeout(30000);
test('some test title', async () => {
const foo = true;
await new Promise((r) => setTimeout(r, 2000));
expect(foo).toBeDefined();
});
Example 2: jest always pass async await
test.only("should not pass", async (done) => {
try {
const a = await getAsync()
expect(a).toEqual(2)
done()
} catch (e) {
// have to manually handle the failed test with "done.fail"
done.fail(e)
}
})