Skip to content
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

asyncWrapper is not executed with act support #1302

Open
lionskape opened this issue Apr 14, 2024 · 3 comments
Open

asyncWrapper is not executed with act support #1302

lionskape opened this issue Apr 14, 2024 · 3 comments

Comments

@lionskape
Copy link

  • @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".
testing-library/user-event#1200

@eps1lon
Copy link
Member

eps1lon commented Apr 15, 2024

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

@kolorfilm
Copy link

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(...)

@lionskape
Copy link
Author

lionskape commented Apr 23, 2024

@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.

asyncWrapper: async cb => {
const previousActEnvironment = getIsReactActEnvironment()
setReactActEnvironment(false)
try {
const result = await cb()
// Drain microtask queue.
// Otherwise we'll restore the previous act() environment, before we resolve the `waitFor` call.
// The caller would have no chance to wrap the in-flight Promises in `act()`
await new Promise(resolve => {
setTimeout(() => {
resolve()
}, 0)
if (jestFakeTimersAreEnabled()) {
jest.advanceTimersByTime(0)
}
})
return result
} finally {
setReactActEnvironment(previousActEnvironment)
}
},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants