-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
renderHook: Context Provider, state change in child function act() error #1206
Comments
Your imports suggest you are using |
Getting this as well for a hook that sets state in an effect. Everywhere on the internet tells to use There is nothing to |
@dev-frid await waitFor(() => {
expect(mockFunction).toHaveBeenCalled();
}) |
It may not help in your case (if there is truely nothing to |
Thanks, guys for all your input, I took my eyes away from this thread for a wee while too long. will look through the comments and see what I can do with my code to rectify the issue I have. Thanks all! |
I have a custom hook that uses a Context Provider for global state management. I am passing a dispatch and data from the state taken from the context inside the hook to a function that will at the end of requesting data from an endpoint dispatch this data coursing a state update inside the context API Provider passed down to the custom hook.
The issue is when I test the custom hook with a wrapper of the Context Provider passed into renderHook() function, I get in the test run the dreaded "act()" error of:
you can see the full explanation at: https://stackoverflow.com/questions/76157226/react-hooks-testing-library-context-provider-state-change-in-child-function-ac
The useUserSearch Hook:
FetchUsers function:
StoreProvider:
The Test spec file:
The text was updated successfully, but these errors were encountered: