Enzyme: another .find() will cause the previous .find() not able to get .parent()

Created on 27 Nov 2018  路  15Comments  路  Source: enzymejs/enzyme

Current behavior

another .find() will cause the previous .find() not able to get .parent()

Expected behavior

should be able to get .parent(), it was ok in v3.3.0

Your environment

API

  • [X] shallow
  • [ ] mount
  • [ ] render

Version

| library | version
| ------------------- | -------
| enzyme | 3.7.0
| react| 16.6.3
| react-dom | 16.6.3
| enzyme-adapter-react-16 | 1.7.0

Adapter

  • [X] enzyme-adapter-react-16
  • [ ] enzyme-adapter-react-16.3
  • [ ] enzyme-adapter-react-16.2
  • [ ] enzyme-adapter-react-16.1
  • [ ] enzyme-adapter-react-15
  • [ ] enzyme-adapter-react-15.4
  • [ ] enzyme-adapter-react-14
  • [ ] enzyme-adapter-react-13
  • [ ] enzyme-adapter-react-helper
  • [ ] others ( )

Details

please check the code here, https://codesandbox.io/s/54j70o404k

import React from "react";

import Enzyme, { shallow } from "enzyme";
import Adapter from "enzyme-adapter-react-16";

Enzyme.configure({ adapter: new Adapter() });

it("another find causing bug", () => {
  class TestComponent extends React.Component {
    render() {
      return (
        <div>
          <h1>Title</h1>
          <span key="1">1</span>
          <span key="2">2</span>
        </div>
      );
    }
  }
  const component = shallow(<TestComponent />);
  const cards = component.find("span");
  expect(cards).toHaveLength(2);

  // #region select another component, comment out this region
  const title = component.find("h1");
  expect(title).toHaveLength(1);
  expect(title.text()).toBe("Title");
  // #endregion

  // failed since 3.4.0, was able to pass in 3.3.0
  // comment out the region above to make this passes
  expect(
    cards
      .at(0)
      .parent()
      .is("div")
  ).toBe(true);
});

update: I cloned the codesandbox with the latest dependencies but still fail, https://codesandbox.io/s/y3nrx89vwx

shallow bug help wanted

Most helpful comment

Working on it.

All 15 comments

Thanks - I think this is a duplicate of #1876.

However, it also might have been fixed in #1811 / #1781 which fixed #1780, and is released in enzyme v3.7. Can you try updating to that? (also, please fill out the entire issue template; it's there for a reason)

I'm using v3.7 in the codesandbox, still have the same issue

updated to use issue template

Thank you, the codesandbox is a perfect repro case, and this is definitely a serious bug.

Working on it.

Are there any news with respect to this issue?

Yes been working on it and have made progress. Will have something up by next week.

Awesome news!

@sstern6 any update?

@plemasantos got side tracked with personal stuff, would you like to take it?

@plemasantos bump

@sstern6 sorry also got caught up for some weeks. Were you able to tackle it?

Any progress updates on this @sstern6? Thanks.

Yes hoping to wrap this up this week, thanks for following up.

Was this page helpful?
0 / 5 - 0 ratings