question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[jest] Testing with @testing-library/react-hooks

See original GitHub issue

Hi,

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:closed
  • Created 3 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ivancuriccommented, Mar 30, 2021

I updated the wiki. Didn’t know anyone could do it without a PR of some sort.

1reaction
xD3CODERcommented, Jan 8, 2021

@3nvi I confirm that it works, thank’s for your help

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found