Open nstepien opened 2 weeks ago
I know the README mentions that this library does not use
act
, but maybe it should?
Wrapping in act
is not required to work properly in the actual browser. The only difference it makes is a warning in the console because react
designed it that way. We need to find a way to disable this warning.
But indeed it may be required for render
specifically because we call this method ourselves. Although the same happens in the dev environment 🤔
Wouldn't it be better to use act
? 🤔
As I understand it, using act
ensures React fully (re-)renders and trigger all the effects following the actions that happened in its callback. Without it there may be timing issues, especially with useEffect
.
Wouldn't it be better to use act? 🤔
This is explained in the docs:
Instead, you should use Vitest's locators and expect.element API that have retry-ability mechanism baked in.
All actions should happen as they would in the browser because we don't interfere with react
directly.
I'm not 100% convinced this is a good idea, without act
you may be testing an intermediary state rather than the final render+effect state.
All actions should happen as they would in the browser
Sure, but tests run faster than a real user would interact with a page, can we be sure that we won't miss anything without act
?
Sure, but tests run faster than a real user would interact with a page, can we be sure that we won't miss anything without
act
?
Yes, we can. Vitest uses CDP and webdriver to communicate with the browser, it doesn't fake events. This is how all e2e tools work, there is no need to rely on framework specific behaviours.
We should wrap rendering and rerendering in the act
method
This is enough for me to get an act warning from React:
Wrapping the
render
call withact
resolves the warning, of course:I know the README mentions that this library does not use
act
, but maybe it should?