React-hooks-testing-library: Exceeded timeout of 5000ms when using redux-thunk with promise

Created on 14 Dec 2019  路  5Comments  路  Source: testing-library/react-hooks-testing-library

I have created a hook that loads data if it's not already loaded, to do so i am using redux-thunk and returning a promise to indicate that its loading data.

It is advised that using waitForNextUpdate for async operation, but using this function will cause "Exceeded timeout" error.

please refer to codesandbox for reproduction.

  • react-hooks-testing-library version: 3.2.1
  • react-test-renderer version: 16.12.0
  • react version: 16.12.0

Relevant code or config:

codesandbox

What you did:

i have tried waitForNextUpdate and waitForValueToChange whithout succeess.

What happened:

will throw exceeded timeout of 5000ms error.

bug

Most helpful comment

i had to update the react-test-renderer to the latest version

Just to clarify, the react-test-renderer version has to match the react version you are using.

All 5 comments

The async utils rely on the hook rerendering to resolve the promise. Try logging out in your hook, in useEffect and between renderHook and await waitForNextUpdate() and make sure the renders are happening when you think they're happening.

I notice as well that you haven't wrapped your hook in react-redux's Provider to provide a store instance with the thunk middleware set up. I'm not familiar with the new hooks for redux, but traditionally this would result in an error when dispatching, so I'm may be worth checking that the dispatch is doing what you want too.

Indeed, the problem was not wrapping the hook in provider, sorry for wasting your time.

Glad I could help :smiley:

Just in case it helps someone else, there were two problems with my implementation:

  1. I forgat to wrap the hook with the redux provider
  2. i had to update the react-test-renderer to the latest version

i had to update the react-test-renderer to the latest version

Just to clarify, the react-test-renderer version has to match the react version you are using.

Was this page helpful?
0 / 5 - 0 ratings