Skip to content

Commit

Permalink
feat(wait): remove default no-op callback (#461)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: If you used `wait()` in the past, you now have to supply a callback. Relying on the "next tick" is an implementation detail and should be avoided in favor of explicit expecations within your wait callback.
  • Loading branch information
kentcdodds committed Mar 4, 2020
1 parent aef3df1 commit 734ec39
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
7 changes: 3 additions & 4 deletions src/__tests__/wait.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ test('it waits for the data to be loaded', async () => {
})

test('wait defaults to a noop callback', async () => {
const handler = jest.fn()
Promise.resolve().then(handler)
await wait()
expect(handler).toHaveBeenCalledTimes(1)
await expect(wait()).rejects.toMatchInlineSnapshot(
`[Error: wait callback is required]`,
)
})

test('can timeout after the given timeout time', async () => {
Expand Down
5 changes: 4 additions & 1 deletion src/wait.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import {getConfig} from './config'

function wait(
callback = () => {},
callback,
{
container = getDocument(),
timeout = getConfig().asyncUtilTimeout,
Expand All @@ -22,6 +22,9 @@ function wait(
},
} = {},
) {
if (!callback) {
return Promise.reject(new Error('wait callback is required'))
}
if (interval < 1) interval = 1
return new Promise((resolve, reject) => {
let lastError
Expand Down

0 comments on commit 734ec39

Please sign in to comment.