diff --git a/src/__tests__/wait-for.js b/src/__tests__/wait-for.js index f4cf0a6c..4ba4702d 100644 --- a/src/__tests__/wait-for.js +++ b/src/__tests__/wait-for.js @@ -1,3 +1,4 @@ +import {renderIntoDocument} from './helpers/test-utils' import {waitFor} from '../' test('waits callback to not throw an error', async () => { @@ -32,3 +33,13 @@ test('uses generic error if there was no last error', async () => { ).catch(e => e) expect(result).toMatchInlineSnapshot(`[Error: Timed out in waitFor.]`) }) + +test('throws nice error if provided callback is not a function', () => { + const {queryByTestId} = renderIntoDocument(` +
+ `) + const someElement = queryByTestId('div') + expect(() => waitFor(someElement)).toThrow( + 'Received `callback` arg must be a function', + ) +}) diff --git a/src/wait-for.js b/src/wait-for.js index 376594d5..a7a35f68 100644 --- a/src/wait-for.js +++ b/src/wait-for.js @@ -22,6 +22,10 @@ function waitFor( }, } = {}, ) { + if (typeof callback !== 'function') { + throw new TypeError('Received `callback` arg must be a function') + } + // created here so we get a nice stacktrace const timedOutError = new Error('Timed out in waitFor.') if (interval < 1) interval = 1