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

parents: cannot read property 'reverse' of null #1780

Closed
ahuth opened this issue Aug 20, 2018 · 3 comments
Closed

parents: cannot read property 'reverse' of null #1780

ahuth opened this issue Aug 20, 2018 · 3 comments

Comments

@ahuth
Copy link
Contributor

ahuth commented Aug 20, 2018

Describe the bug
Calling parents sequentially on two different sibling nodes breaks. I'm on:

  • enzyme 3.4.4
  • enzyme-adapter-react-16 1.2.0
TypeError: Cannot read property 'reverse' of null
    at parentsOfNode (http://localhost:9876/base/frontend/react-specs.js:41255:32)
    at ShallowWrapper.<anonymous> (http://localhost:9876/base/frontend/react-specs.js:62256:50)
    at ShallowWrapper.single (http://localhost:9876/base/frontend/react-specs.js:62811:25)
    at ShallowWrapper.parents (http://localhost:9876/base/frontend/react-specs.js:62255:41)
    at UserContext.<anonymous> (http://localhost:9876/base/frontend/react-specs.js:248367:18)
    at attempt (http://localhost:9876/base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:4289:46)
    at QueueRunner.run (http://localhost:9876/base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:4217:20)
    at QueueRunner.execute (http://localhost:9876/base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:4199:10)
    at Spec.queueRunnerFactory (http://localhost:9876/base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:909:35)
    at Spec.execute (http://localhost:9876/base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:526:10)

To Reproduce
The following test will reproduce the issue:

it('breaks', () => {
  class Test extends React.Component {
    render() {
      return (
        <div>
          <div className="a">
            <div>A child</div>
          </div>
          <div className="b">
            <div>B child</div>
          </div>
        </div>
      );
    }
  }

  const wrapper = shallow(<Test />);

  const aChild = wrapper.find({ children: 'A child' });
  const bChild = wrapper.find({ children: 'B child' });

  aChild.parents({ className: 'a' });
  bChild.parents({ className: 'b' });
});

Expected behavior
It should not throw an error.

Desktop (please complete the following information):

  • OS: macOS 10.13.6
  • Browser Chrome
  • Version 68.0.3440.106 (Official Build) (64-bit)

Additional context
In the above example, changing the order of accessing parents works:

const aChild = wrapper.find({ children: 'A child' });
aChild.parents({ className: 'a' });

const bChild = wrapper.find({ children: 'B child' });
bChild.parents({ className: 'b' });
@ljharb
Copy link
Member

ljharb commented Aug 21, 2018

Related to #410; thanks for the report.

@ljharb
Copy link
Member

ljharb commented Aug 21, 2018

Your test case was very helpful; there's something very worrying going on here.

I've put up #1781 to track a fix.

@ahuth
Copy link
Contributor Author

ahuth commented Aug 22, 2018

Thanks for digging into it! @juanca and I may look into your PR, as well, and see if we can help

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

No branches or pull requests

2 participants