Skip to content

Commit 0083286

Browse files
author
Kent C. Dodds
committed
fix(wait): be explicit about the timeout and interval
1 parent 69a395f commit 0083286

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

README.md

+14-3
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,20 @@ getByLabelText('username').value = 'chucknorris'
276276
// ...
277277
```
278278

279-
This can be useful when (for example) you integration test your apollo-connected
280-
react components that go a couple level deep, with queries fired up in
281-
consequent components.
279+
This can be useful if you have a unit test that mocks API calls and you need
280+
to wait for your mock promises to all resolve. This can also be useful when
281+
(for example) you integration test your apollo-connected react components that
282+
go a couple level deep, with queries fired up in consequent components.
283+
284+
The default `callback` is a no-op function (used like `await wait()`). This can
285+
be helpful if you only need to wait for one tick of the event loop.
286+
287+
The default `timeout` is `4500ms` which will keep you under
288+
[Jest's default timeout of `5000ms`](https://facebook.github.io/jest/docs/en/jest-object.html#jestsettimeouttimeout).
289+
290+
The default `interval` is `50ms`. However it will run your callback immediately
291+
on the next tick of the event loop (in a `setTimeout`) before starting the
292+
intervals.
282293

283294
## Custom Jest Matchers
284295

src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function flushPromises() {
2525
return new Promise(resolve => setImmediate(resolve))
2626
}
2727

28-
function wait(callback = () => {}, {timeout, interval} = {}) {
28+
function wait(callback = () => {}, {timeout = 4500, interval = 50} = {}) {
2929
return waitForExpect(callback, timeout, interval)
3030
}
3131

0 commit comments

Comments
 (0)