no-unnecessary-act false positive for new React.act ?!
Closed this issue · 1 comments
What rule do you want to change?
no-unnecessary-act
Does this change cause the rule to produce more or fewer warnings?
More warnings
How will the change be implemented?
check if no-unnecessary-act rule applies correctly to the new act
of react
Example code
Since the latest react release it seems to be necessary to wrap state changes with the new act
of react:
When testing, code that causes React state updates should be wrapped into act(...):
act(() => {
/* fire events that update state */
});
/* assert on the output */
Implementation:
import { act } from 'react'
await act(async () => {
await userEvent.click(radioButton)
})
How does the current rule affect the code?
This is wrongful (?!) picked up by testing-library/no-unnecessary-act
How will the new rule affect the code?
if possible, consider act
coming from react
could be ignored
Anything else?
No response
Do you want to submit a pull request to change the rule?
No
I don't think act
usage itself has changed: if you write your tests without a framework, you wrap the state changes within act
, but if using React Testing Library it will wrap actions in act
for you so it's unnecessary.
It seems only the reexport itself changed, but this util was already available. React Testing Library was already using this util to enhance its own act
.
Unless there is something officially announced about act
working differently, the rule should work the same way.