Skip to content

Commit 22dd1f0

Browse files
committed
Final API
1 parent c25b253 commit 22dd1f0

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

docs/web-testing-library/api.mdx

+24-6
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ calling them.
1717
function waitFor<T>(
1818
callback: () => T | Promise<T>,
1919
options?: {
20-
timeout?: number
2120
interval?: number
2221
onTimeout?: (error: Error) => Error
22+
showOriginalStackTrace?: boolean
23+
signal?: AbortSignal
24+
timeout?: number
2325
},
2426
): Promise<T>
2527
```
@@ -47,10 +49,26 @@ implicitly with `async` syntax), then the `waitFor` utility will not call your
4749
callback again until that promise rejects. This allows you to `waitFor` things
4850
that must be checked asynchronously.
4951

50-
The default `interval` is `50ms`. However it will run your callback immediately
51-
before starting the intervals.
52+
The default `interval` is `50ms`. However, it runs your callback
53+
immediatelybefore starting the intervals.
5254

53-
The default `timeout` is `1000ms`.
55+
The `onTimeout` callback receives the error with which `waitFor` should reject.
56+
You can return a more detailed error with which `waitFor` should reject. For
57+
example, in a DOM you can return a snapshot of the DOM at the time `waitFor`
58+
timed out.
5459

55-
The default `onTimeout` receives the error which should hopefully make it easier
56-
to track down what caused the timeout.
60+
You can pass an
61+
[`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) if
62+
you want `waitFor` to stop checking the callback (e.g. if you want it to race
63+
against other observers like
64+
[`MutationObserver`](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver/MutationObserver)).
65+
`waitFor` will then reject with the
66+
[`reason` of the given `AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/reason).
67+
68+
By default, `waitFor` will reject with the stack trace of the `waitFor` call.
69+
This is usually the more relevant stack trace for developers. However, you might
70+
want to trace the last call to the given `callback` that caused `waitFor` to
71+
reject. Then you can pass `showOriginalStackTrace: true`. We don't recommend
72+
using it unless you know what you're doing.
73+
74+
The default `timeout` is `1000ms`.

0 commit comments

Comments
 (0)