[jest] Testing with @testing-library/react-hooks
See original GitHub issueHi,
First thank’s for this amazing library !
I have an issue when I try to test some store with @testing-library/react-hooks
I get this error even if I wrap my updating state call in act()
.
console.error
Warning: An update to TestHook inside a test was not wrapped in act(...).
When testing, code that causes React state updates should be wrapped into act(...):
act(() => {
/* fire events that update state */
});
/* assert on the output */
My code:
it('should pass if user logged', () => {
const { result, waitForNextUpdate } = renderHook(() =>
userStore((state) => state)
)
act(() => result.current.setUserLogged(true))
...
})
Thank’s
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
How to test React Hooks - LogRocket Blog
The goal of this article is to provide a practical guide on testing React Hooks using tools such as React Testing Library, Jest,...
Read more >A Complete Guide to Testing React Hooks - Toptal
One can test React Hooks using a library such as react-hooks-testing-library. Testing a hook is similar to testing React components, and this library...
Read more >React Hooks Testing Library: Introduction
The react-hooks-testing-library allows you to create a simple test harness for React hooks that handles running them within the body of a function...
Read more >React Hooks Testing Library - GitHub
The react-hooks-testing-library allows you to create a simple test harness for React hooks that handles running them within the body of a function...
Read more >An Easy Guide to Testing React Hooks - OpenReplay Blog
Jest is hands down the most popular testing library for React components and it was build by the Jest team at Facebook and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I updated the wiki. Didn’t know anyone could do it without a PR of some sort.
@3nvi I confirm that it works, thank’s for your help