Skip to content

Commit 584c806

Browse files
committed
rfc(error): improve timeout error stack trace for waitFor
1 parent bbef100 commit 584c806

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/wait.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,14 @@ export function waitFor<T>(getter: () => T, options: {
3434
return new Promise(rs => setTimeout(rs, options.interval)).then(wait);
3535
}
3636

37+
// We generate the error here to capture the stack trace, but we will only throw it if it times out
38+
const timeoutError = new Error(options.present ? 'Element not found' : 'Element not removed');
39+
3740
return Promise.race([
3841
new Promise(
3942
(_, rj) => setTimeout(() => {
4043
timedOut = true;
41-
rj(new Error(options.present ? 'Element not found' : 'Element not removed'));
44+
rj(timeoutError);
4245
}, options.timeout)
4346
),
4447
wait()

0 commit comments

Comments
 (0)