-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Hooks-based state does not persist between >1 interactions #2333
Comments
This is not a bug related to Hooks. Here's the same repro with a class: https://codesandbox.io/s/lively-wildflower-rhez6. Stepping through the debugger, I see that although However, the next time Enzyme asserts props, it uses the previous |
@robchristian you're using enzyme v3.8, which predates hooks and has had lots of bugs fixed since; can you upgrade to v3.11 and see if the issue still occurs? |
However, I see that both sandboxes still fail on 3.11, so I'll dig into this further. Thanks for the repros! |
Any update on this @ljharb ? |
Current behavior
Functional component that uses
useState
to increment a counter, can't increment more than once in tests.I will link to other issues which appear to be either very similar, or actual duplicates. Because every instance I find appears to complicate the issue, I wanted to open this to provide a more simple repro. It shows a simple counter, note that the first 2 tests pass, but the last fails:
https://codesandbox.io/s/staging-forest-iycsj?fontsize=14&hidenavigation=1&module=%2Fsrc%2FApp.test.js&previewwindow=tests&theme=dark
I've tried every combination of
act()
andwrapper.update()
, I can conceive of, as well aswrapper.setProps(wrapper.props())
. This last one I tried because somewhere in a doc or guide it said that.setProps
must be called to force the component to re-render. But because my test doesn't involve changing props, I attempted passing the current props.Expected behavior
Functional component that uses
useState
in increment a counter should maintain state across each call toonClick
handler, and show expected state when inspected through various means, such as.props()
,.debug()
,.text()
, etc.Your environment
MacOS Mojave v10.14.6
NodeJS v10.16.3
API
Version
Adapter
Related Issues
#2305, #1570, #1996. Probably others that I can't quickly find from browser history.
The text was updated successfully, but these errors were encountered: