Skip to content

Commit

Permalink
fix(wait): be explicit about the timeout and interval
Browse files Browse the repository at this point in the history
  • Loading branch information
Kent C. Dodds committed Mar 29, 2018
1 parent 69a395f commit 0083286
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
17 changes: 14 additions & 3 deletions README.md
Expand Up @@ -276,9 +276,20 @@ getByLabelText('username').value = 'chucknorris'
// ...
```

This can be useful when (for example) you integration test your apollo-connected
react components that go a couple level deep, with queries fired up in
consequent components.
This can be useful if you have a unit test that mocks API calls and you need
to wait for your mock promises to all resolve. This can also be useful when
(for example) you integration test your apollo-connected react components that
go a couple level deep, with queries fired up in consequent components.

The default `callback` is a no-op function (used like `await wait()`). This can
be helpful if you only need to wait for one tick of the event loop.

The default `timeout` is `4500ms` which will keep you under
[Jest's default timeout of `5000ms`](https://facebook.github.io/jest/docs/en/jest-object.html#jestsettimeouttimeout).

The default `interval` is `50ms`. However it will run your callback immediately
on the next tick of the event loop (in a `setTimeout`) before starting the
intervals.

## Custom Jest Matchers

Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Expand Up @@ -25,7 +25,7 @@ function flushPromises() {
return new Promise(resolve => setImmediate(resolve))
}

function wait(callback = () => {}, {timeout, interval} = {}) {
function wait(callback = () => {}, {timeout = 4500, interval = 50} = {}) {
return waitForExpect(callback, timeout, interval)
}

Expand Down

0 comments on commit 0083286

Please sign in to comment.