react-testing-library icon indicating copy to clipboard operation
react-testing-library copied to clipboard

asyncWrapper is not executed with act support

Open lionskape opened this issue 1 year ago • 3 comments

  • @testing-library/react version: 14.2.2
  • Testing Framework and version: jest, 29.7
  • DOM Environment: "jest-environment-jsdom": "29.7.0"

Relevant code or config:

        const {user} = setup(<ControlDate onChange={jest.fn()} />);
        const input = screen.getByRole('textbox');
        await act(async () => {
            await user.type(input, '01.10.2015');
        });
        await act(async () => {
            await user.type(input, '02.12.2012');
        });

What you did:

I'm running events using user-events pacakge - https://github.com/testing-library/user-event

What happened:

Looks like it is executed in AsyncWrapper and make a lot of noise about "non-act environment". https://github.com/testing-library/user-event/discussions/1200

lionskape avatar Apr 14 '24 21:04 lionskape

This may be an issue with user-event. Can you provide a reproduction witout use-event or at least the important bits inlined?

eps1lon avatar Apr 15 '24 18:04 eps1lon

I have the same problem:

For instance:

await act(async () => await userEvent.click(screen.getByTestId('backIcon')));

gives me the same error:

console.error
    Warning: The current testing environment is not configured to support act(...)

kolorfilm avatar Apr 18 '24 08:04 kolorfilm

@eps1lon sorry, I do not have reproduction without user-event

But, as I understand from user-event issues (linked in my first message) - the problem is an AsyncWrapper implementation. User event is running inside AsyncWrapper, which is "non-act" environment.

https://github.com/testing-library/react-testing-library/blob/edb6344d578a8c224daf0cd6e2984f36cc6e8d86/src/pure.js#L37-L59

lionskape avatar Apr 23 '24 08:04 lionskape