Skip to content

Commit f629b4c

Browse files
committed
feat(wait): remove default no-op callback
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.
1 parent 5fae126 commit f629b4c

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/__tests__/wait.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ test('it waits for the data to be loaded', async () => {
1212
})
1313

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

2120
test('can timeout after the given timeout time', async () => {

src/wait.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
import {getConfig} from './config'
1010

1111
function wait(
12-
callback = () => {},
12+
callback,
1313
{
1414
container = getDocument(),
1515
timeout = getConfig().asyncUtilTimeout,
@@ -22,6 +22,9 @@ function wait(
2222
},
2323
} = {},
2424
) {
25+
if (!callback) {
26+
return Promise.reject(new Error('wait callback is required'))
27+
}
2528
if (interval < 1) interval = 1
2629
return new Promise((resolve, reject) => {
2730
let lastError

0 commit comments

Comments
 (0)