Skip to content

Commit bde4cf5

Browse files
committed
feat(waitFor): improve error message for non-function callbacks
1 parent f3f84ce commit bde4cf5

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/__tests__/wait-for.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,9 @@ test('uses generic error if there was no last error', async () => {
3232
).catch(e => e)
3333
expect(result).toMatchInlineSnapshot(`[Error: Timed out in waitFor.]`)
3434
})
35+
36+
test('throws nice error if provided callback is not a function', () => {
37+
expect(() => waitFor('not a function')).toThrow(
38+
'Received `callback` arg must be a function',
39+
)
40+
})

src/wait-for.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ function waitFor(
2222
},
2323
} = {},
2424
) {
25+
if (typeof callback !== 'function') {
26+
throw new Error('Received `callback` arg must be a function')
27+
}
28+
2529
// created here so we get a nice stacktrace
2630
const timedOutError = new Error('Timed out in waitFor.')
2731
if (interval < 1) interval = 1

0 commit comments

Comments
 (0)