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.1react-test-renderer version: 16.12.0react version: 16.12.0i have tried waitForNextUpdate and waitForValueToChange whithout succeess.
will throw exceeded timeout of 5000ms error.
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:
react-test-renderer to the latest versioni 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.
Most helpful comment
Just to clarify, the
react-test-rendererversion has to match thereactversion you are using.