question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Simulate failing on after updating react and enzyme version

See original GitHub issue

After updating enzyme version, a lot of tests seem to be failing for no reason. Here’s a change history of my packages -

react: 16.4.2 -> 16.8.4 react-dom: 16.4.2 -> 16.8.4 enzyme: 3.3.0 -> 3.9.0 enzyme-adapter-react-16: 1.1.1 -> 1.11.2 react-test-renderer: 16.8.1 - 16.8.2

  • Expected value to be truthy, instead received
    false
    
    51 |     sidebarComp.instance().toggle();
    52 |     sidebarComp.update();
    53 |     **expect(sidebarComp.state().visible).toBeTruthy();**
    54 |   });
    

toggle = () => { this.setState(prevState => { return { visible: !prevState.visible }; }); };

  • ShallowWrapper::update() can only be called when wrapping one node
    
    37 |     const expandButton = component.find('button');
    38 |     expect(expandButton).toHaveLength(1);
    39 |     **expandButton.simulate('click');**
    40 |     expect(component.state().expanded).toBeTruthy();
    41 |   });
    42 | });
    

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
pgangwanicommented, Mar 18, 2019

@anmoltw : I got it. You have to wrap map(JSX) output with <Fragment> or <> where as I didnt see any issue with SideBar testing

Here you go ==> https://codesandbox.io/s/w6183xxjr8 Refer: Hello.js : Line: 19,25 (wrapping)

I prefer to use props().onClick over simulate (thats Ok for this case) when using shallow mount (which I love too) Please let me know if any other issue after suggested change.

@ljharb Please add explanation/extra details if I missed any.

0reactions
ljharbcommented, Apr 6, 2019

@anmoltw sorry for the delay; can you prepare a new sandbox that highlights the remaining issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Simulate failing on after updating react and enzyme version
After updating enzyme version, a lot of tests seem to be failing for no reason. Here's a change history of my packages -...
Read more >
React input onchange simulation not updating value using ...
the problem is that simulation of the event is not updating state. I tried wrapper.update() as well but it is not working. you...
Read more >
Change Log · Enzyme - GitHub Pages
explain why need to re-call .find() after update (#2140); shallow : fix childAt (#2134); Update v2 -> v3 migration guide re props after...
Read more >
enzyme-adapter-react-15 - npm
JavaScript Testing utilities for React. Latest version: 1.4.4, last published: 2 months ago. Start using enzyme-adapter-react-15 in your ...
Read more >
Continuous integration for React applications using Jest and ...
npm install --save-dev enzyme enzyme-adapter-react-16 ... object to simulate a click event sent by the browser when the button is clicked.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found