waitForNextUpdate of renderHook times out or is missing
waitForNextUpdate times out in a renderHook testShort answer
The renderHook that ships in @testing-library/react returns result, rerender and unmount, and no waitForNextUpdate. Wait with waitFor and assert on result.current, which holds the last committed value. waitFor retries a throwing callback for one second by default, so a slow update needs a larger timeout.
Fix it fast
1Find out which cause you have
Check where renderHook is imported from, and what the result object contains.
grep -rn "renderHook" src/ | head npm ls @testing-library/react @testing-library/react-hooks2Match what you see, then jump to its fix
- 1
The destructuring has { result, waitForNextUpdate }The test still uses the old waitForNextUpdate helperFix - 2
waitFor fails after about one second, and result.current still holds the initial valueThe expected state does not arrive within the default timeoutFix - 3
The test ends before the assertion, or the assertion error appears after the testThe wait is not awaitedFix
- 1
What does the error look like?
waitForNextUpdate times out in a renderHook testwaitFor on result.current fails after about one second
Cause 1 of 3
The test still uses the old waitForNextUpdate helper
1Check
The react-hooks README says the package is deprecated and renderHook moved into @testing-library/react. The renderHook API page lists result, rerender, unmount and the options, and shows no waitForNextUpdate.
grep -rn "waitForNextUpdate" src/2Fix
Import renderHook and waitFor from @testing-library/react and wait for the value you expect.
import { renderHook, waitFor } from '@testing-library/react';
const { result } = renderHook(() => useUser(42));
await waitFor(() => expect(result.current.user).toEqual({ id: 42 }));3Verify
The test passes and no longer names waitForNextUpdate.
npx jest src/useUser.test.jsConfirmed by raw.githubusercontent.com
Cause 2 of 3
The expected state does not arrive within the default timeout
1Check
The async utilities page says waitFor retries a callback that throws, with a default timeout of 1000ms and an interval of 50ms. The renderHook page says result.current is the most recently committed value.
console.log(result.current)2Fix
Make sure the hook's request is mocked and resolves, then raise the timeout only if the work is legitimately slow.
await waitFor(
() => expect(result.current.loading).toBe(false),
{ timeout: 3000 }
);3Verify
The assertion passes within the new limit.
npx jest src/useUser.test.jsConfirmed by testing-library.com
Cause 3 of 3
The wait is not awaited
1Check
The async utilities page states these methods return Promises, so they need await or .then.
grep -rn "waitFor(" src/ | grep -v await2Fix
Make the test function async and await every waitFor.
it('loads the user', async () => {
const { result } = renderHook(() => useUser(42));
await waitFor(() => expect(result.current.loading).toBe(false));
});3Verify
A deliberately wrong expectation now fails the test.
npx jest src/useUser.test.jsConfirmed by testing-library.com
How do I stop it coming back?
- Assert on result.current inside waitFor, never on a value copied earlier.
- Mock network calls in hook tests so the update time does not depend on a server.
- Await every async test utility.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
Related fixes
Web apps
Testing a custom hook fails after upgrading to React 18
renderHook import still comes from @testing-library/react-hooks
The package @testing-library/react-hooks is deprecated and aimed at older React.
3 causes, each with a fixWeb apps
Module not found for antd/dist/antd.less after upgrading to Ant Design 5
Module not found: Error: Can't resolve 'antd/dist/antd.less'
Ant Design 5 dropped Less and the bundled CSS file for CSS-in-JS, so antd/dist/antd.less no longer exists.
3 causes, each with a fixWeb apps
Astro Code component fails inside a React component
Astro components cannot be rendered directly via function call
Astro components such as Code only exist on the server and render static HTML.
2 causes, each with a fixWeb apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
How to catch and handle a 422 from Axios in a Redux thunk
action.error.message is 'Rejected' and action.payload is undefined
A 422 means the server read the request but cannot process its content, so repeating it unchanged fails again.
4 causes, each with a fixWeb apps
axios gets 429 Too Many Requests from a React app
429 (Too Many Requests)
A 429 comes from the server or an API gateway, not from axios: your client sent too many requests in a window.
4 causes, each with a fix