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

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

Open
2 of 13 tasks
kambing86 opened this issue Nov 27, 2018 · 15 comments · May be fixed by #2061
Open
2 of 13 tasks

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

kambing86 opened this issue Nov 27, 2018 · 15 comments · May be fixed by #2061

Comments

@kambing86
Copy link

kambing86 commented Nov 27, 2018

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

  • 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

  • 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

@ljharb
Copy link
Member

ljharb commented Nov 28, 2018

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)

@kambing86
Copy link
Author

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

@kambing86
Copy link
Author

updated to use issue template

@ljharb
Copy link
Member

ljharb commented Nov 29, 2018

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

@sstern6
Copy link
Contributor

sstern6 commented Dec 6, 2018

Working on it.

@plemasantos
Copy link

Are there any news with respect to this issue?

@sstern6
Copy link
Contributor

sstern6 commented Feb 8, 2019

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

@plemasantos
Copy link

Awesome news!

@plemasantos
Copy link

@sstern6 any update?

@sstern6
Copy link
Contributor

sstern6 commented Mar 10, 2019

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

@sstern6
Copy link
Contributor

sstern6 commented Mar 16, 2019

@plemasantos bump

@sstern6
Copy link
Contributor

sstern6 commented Mar 19, 2019

#2061

@sstern6 sstern6 linked a pull request Mar 20, 2019 that will close this issue
@plemasantos
Copy link

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

ljharb pushed a commit to sstern6/enzyme that referenced this issue Apr 6, 2019
…dUpdateComponent` method before updating the wrapper.

Fixes enzymejs#1916.
ljharb pushed a commit to sstern6/enzyme that referenced this issue Apr 23, 2019
…dUpdateComponent` method before updating the wrapper.

Fixes enzymejs#1916.
@ztoben
Copy link

ztoben commented Apr 29, 2019

Any progress updates on this @sstern6? Thanks.

@sstern6
Copy link
Contributor

sstern6 commented Apr 29, 2019

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

ljharb pushed a commit to sstern6/enzyme that referenced this issue Sep 28, 2019
…dUpdateComponent` method before updating the wrapper.

Fixes enzymejs#1916.
ljharb pushed a commit to sstern6/enzyme that referenced this issue Dec 21, 2020
…dComponentUpdate` method before updating the wrapper.

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

Successfully merging a pull request may close this issue.

5 participants