Is your feature request related to a problem? Please describe.
React 16.8 introduced act() to allow component interactions to be tested in a synchronous way.
Describe the solution you'd like
wrapper.simulate() should be wrapped in act() to ensure any state changes are resolved before proceeding.
Describe alternatives you've considered
act(() => {
wrapper.simulate();
});
Though it's easy to forget act.
Additional context
I have a feeling this is already on your roadmap, but I couldn't find an issue about it.
This is already addressed by #2034.
Out of curiosity, does that PR mean that any time a mounted component is rendered, it's wrapped in act()? Or only on mount()?
Only mount mounts components, so yes to both?
Shallow rendering does not yet have an “act”, so that’s still unaddressed.
@ljharb sorry how does #2034 address this? It seems like that only wraps mount() calls in act()? simulate() should _also_ wrap calls, which is not what's happening on the latest published enzyme
@jquense there's a bunch of unpublished stuff in enzyme, for one, but you're right that simulate probably isn't covered. A PR to fix that would be great.
act requires a DOM, and there's no act that works in a non-browser environment, so it's simply not an option for shallow at this time.
Could you re-open this issue then?
It’s not fixable by enzyme until the shallow renderer provides an act, but sure.
But it's not fixable for simulate in full DOM rendering?
Ah, true, that is fixable. PRs welcome :-) even if they only have test cases.
Thanks! I'll try to find time to contribute. I think this will be a huge improvement for users who need to force wrappers to update after simulating events to ensure that state updates are complete.
@mikesteele let me know if you don't have any time . i'd be happy to put something together as well
Feel free to race each other to get something up :-p thanks in advance! <3
@jquense I probably won't have time for a few weeks, feel free to take this