Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

waitForNextUpdate of renderHook times out or is missing

ErrorwaitForNextUpdate times out in a renderHook test

Short 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.

  • Applies to @testing-library/react 16, React 19, Jest 29
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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-hooks
  2. 2Match what you see, then jump to its fix

    1. 1The destructuring has { result, waitForNextUpdate }The test still uses the old waitForNextUpdate helperFix
    2. 2waitFor fails after about one second, and result.current still holds the initial valueThe expected state does not arrive within the default timeoutFix
    3. 3The test ends before the assertion, or the assertion error appears after the testThe wait is not awaitedFix

What does the error look like?

  • waitForNextUpdate times out in a renderHook test
  • waitFor 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.js

Confirmed by raw.githubusercontent.com

Did this fix it?

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.js

Confirmed by testing-library.com

Did this fix it?

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 await

2Fix

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.js

Confirmed by testing-library.com

Did this fix it?

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:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.