Skip to content
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

React Hooks Wrapper not getting updated after state change in useEffect #2463

Open
prabhjot3 opened this issue Oct 27, 2020 · 0 comments
Open

Comments

@prabhjot3
Copy link

prabhjot3 commented Oct 27, 2020

Current behavior
I'm using a functional component with a setState hook in useEffect. The state variable that is set inside useEffect is wrapped over the return statement to render the JSX for the component.

When I debug into it, the component renders with the correct state variable but my wrapper in my test does Not show the correct information.

wrapper.update() isn't fixing this issue.

Below is a snippet of what I am trying to achieve:

const DummyComponent= ({}) => {
const [selected, setSelected] = React.useState(false);

useEffect(() => {
  setSelected(true)
}, [someDependency])

return (
  { 
     selected && (
     <div id= 'container'>
        {childComponents}
      </div>)
   }
);
})

it('test', () => {
const wrapper= mount( );
wrapper.find('container')first().props().onClick();
wrapper = wrapper.update(); // this doesn't fix my problem
expect(wrapper.toMatchSnapshot());
});

I am getting the below error:

Method “props” is meant to be run on 1 node. 0 found instead.

Expected Behaviour

After state update in useEffect re-render should be triggered in test case and element with id="container" should be found.

Note: This is not same as #2305

 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant