From f629b4c464201dbcef518897fc19bcd754382f1a Mon Sep 17 00:00:00 2001 From: "Kent C. Dodds" Date: Wed, 4 Mar 2020 13:19:53 -0700 Subject: [PATCH] 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. --- src/__tests__/wait.js | 7 +++---- src/wait.js | 5 ++++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/__tests__/wait.js b/src/__tests__/wait.js index 70e7a83a..3c815107 100644 --- a/src/__tests__/wait.js +++ b/src/__tests__/wait.js @@ -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 () => { diff --git a/src/wait.js b/src/wait.js index 197ee1fb..9e750320 100644 --- a/src/wait.js +++ b/src/wait.js @@ -9,7 +9,7 @@ import { import {getConfig} from './config' function wait( - callback = () => {}, + callback, { container = getDocument(), timeout = getConfig().asyncUtilTimeout, @@ -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