Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Warning about using different versions of act() when wait()ing on an async effect #173

Closed
Labels
enhancementNew feature or request
@pelotom

Description

  • @testing-library/react-hooks version: 2.0.1
  • react-test-renderer version: 16.9.0
  • react version: 16.9.0
  • node version: 12.9.0
  • npm (or yarn) version: 1.17.3 (yarn)

Relevant code or config:

import { useState, useCallback, useEffect } from 'react';
import { renderHook, act } from '@testing-library/react-hooks';
import { wait } from '@testing-library/react';
test('should increment counter', async () => {
 const { result } = renderHook(useCounter);
 act(result.current.increment);
 expect(result.current.count).toBe(1);
 await wait(() => expect(result.current.count).toBe(2));
});
function useCounter() {
 const [count, setCount] = useState(0);
 useEffect(() => {
 setTimeout(() => {
 setCount(count => count + 1);
 });
 }, []);
 const increment = useCallback(() => setCount(x => x + 1), []);
 return { count, increment };
}

What you did:

Tried to augment the example test in the README with an asynchronous effect.

What happened:

Although the test passes I get a warning about using differing versions of act():

 PASS test/foo.test.tsx
 ✓ should increment counter (13ms)
 console.error node_modules/react-test-renderer/cjs/react-test-renderer.development.js:104
 Warning: It looks like you're using the wrong act() around your test interactions.
 Be sure to use the matching version of act() corresponding to your renderer:
 // for react-dom:
 import {act} from 'react-dom/test-utils';
 //...
 act(() => ...);
 // for react-test-renderer:
 import TestRenderer from 'react-test-renderer';
 const {act} = TestRenderer;
 //...
 act(() => ...);
 in TestHook
 in Suspense

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /