-
-
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
Functional component and useState hooks - wrapper not reflecting changes after rerender triggered by setState #2305
Comments
I'm having the same issue |
Is there any movement on this? I'm seeing the same issue with enzyme@3.11.0 and react@16.8.1. As things stand I can't use React hooks with enzyme. Note |
for unknown reason |
Upgrading to react@16.13.0 fixed the issue. |
@josh08h Same issue on react 16.13.1 |
@makr28 what is |
This seems to work for me in a code sandbox https://codesandbox.io/s/eloquent-violet-x8gjh?file=/src/index.js |
@bdwain "viewer" was a mistake on my part, i copied a test of ours and changed viewer to wrapper to be more generic in my question. I just forgot to change that instance to "wrapper". I haven't gotten a chance to try this. I found a different way to somewhat test what I needed for my project. If everyone else says 16.13.1 fixed this, I'm cool with this getting closed. |
I'm not sure anyone has said this. I'm running 16.13.1 and have this issue. Do anyone have any update on this? 🙏 |
a PR with failing test cases would be appreciated; it's much easier for me to come up with a fix from that. |
I got to this issue and after trying some variants, I think this one solved the problem. The key I think is in updating the wrapper after the update: test('canGoNext should be false initially and true when key has length = 8', () => {
let wrapper = mountWrapper();
let wizard = wrapper.find(Wizard);
expect(wizard.props().canGoNext).toBeFalsy();
const signKey = wrapper.find(SignatureKeyInput);
act(() => {
signKey.props().onChange('12345678');
});
wrapper = wrapper.update();
wizard = wrapper.find(Wizard);
expect(wizard.props().canGoNext).toBeTruthy();
}); |
Current behavior
I'm using a functional component with a setState hook. I am calling a function in the component that uses that setState hook's setter function. The state variable that is set is used in the return of the functional component to pass something to a child component.
When I debug into it, the component renders with the correct state variable and the child component having the correct props But my wrapper in my test does Not show the correct information is being passed to the child component.
wrapper.update() isn't fixing this issue.
Here's a quick basic watered down example of what i am doing (component and test)
Basically the test should set the 2nd item's isSelected to true. It does in the code when I debug, but the wrapper in the test doesn't show those changes.
Expected behavior
I expect item2 isSelected to equal true. When I debug into the code I see the rerender after 'setSelected' is called and it renders with the correctly selected item. In the test I cant see that though. When I do wrapper.debug() it show the old information
Your environment
Windows 10
visual studio code
API
Version
All enzyme stuff in my package.json
"enzyme": "^3.3.0",
"enzyme-adapter-react-16": "^1.1.1",
"enzyme-react-intl": "^1.4.8",
"enzyme-redux": "^0.2.1",
"enzyme-to-json": "^3.3.3",
React Intl:
"react-intl": "^2.3.0",
Adapter
The text was updated successfully, but these errors were encountered: