Skip to content

Commit

Permalink
rfc(error): improve timeout error stack trace for waitFor
Browse files Browse the repository at this point in the history
  • Loading branch information
tomtomau committed Sep 19, 2019
1 parent bbef100 commit 584c806
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/wait.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ export function waitFor<T>(getter: () => T, options: {
return new Promise(rs => setTimeout(rs, options.interval)).then(wait);
}

// We generate the error here to capture the stack trace, but we will only throw it if it times out
const timeoutError = new Error(options.present ? 'Element not found' : 'Element not removed');

return Promise.race([
new Promise(
(_, rj) => setTimeout(() => {
timedOut = true;
rj(new Error(options.present ? 'Element not found' : 'Element not removed'));
rj(timeoutError);
}, options.timeout)
),
wait()
Expand Down

0 comments on commit 584c806

Please sign in to comment.