@@ -17,9 +17,11 @@ calling them.
17
17
function waitFor<T >(
18
18
callback : () => T | Promise <T >,
19
19
options ? : {
20
- timeout? : number
21
20
interval? : number
22
21
onTimeout? : (error : Error ) => Error
22
+ showOriginalStackTrace? : boolean
23
+ signal? : AbortSignal
24
+ timeout? : number
23
25
},
24
26
): Promise <T >
25
27
```
@@ -47,10 +49,26 @@ implicitly with `async` syntax), then the `waitFor` utility will not call your
47
49
callback again until that promise rejects . This allows you to ` waitFor ` things
48
50
that must be checked asynchronously .
49
51
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 .
52
54
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 .
54
59
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