Some additional info to @Klesun answer. One can repeat this with following
test('first test', async () => {
console.error('first test before waitFor');
try {
await waitFor(async () => { throw new Error(''); }, { timeout: 6000 });
} catch (e) { }
console.error('first test after waitFor');
}, 5000);
test('second test', async () => {
console.error('second test before timeout');
await new Promise((r) => setTimeout(r, 6100));
console.error('second test after timeout');
}, 6200);
Where the output will be:
first test before waitFor
second test before timeout
first test after waitFor
second test after timeout
Removing setTimeout from second test will hide "first test after waitFor" since test for this file will be finished.
Additionally this causes true cause of failure to be somewhat hidden. For example if we remove try ... catch
the only thing that will be reported to us will be thrown: "Exceeded timeout of 5000 ms for a test.
for test('first test', async () => {
and not exact spot (waitFor
in this case). This can be a bit cumbersome to track in longer running tests.
I would expect that the best path to track where error lies in these cases would be to increase test timeout.