-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
parent() api does not return children in shallow rendering #1235
Comments
I'm having the same issue with Enzyme 3 (was working with Enzyme 2): test('parent() vs parents()', () => {
const H1 = () => (
<h1 />
);
const root = shallow(
<div id="root">
<H1 />
<h2 />
<h3 />
</div>
);
console.log('root:', root.debug());
const h1 = root.find(H1);
console.log('h1.parent():', h1.parent().debug());
console.log('h1.parents():', h1.parents().debug());
}); Output:
To sum-up |
@tkrotoff @VidyullathaKandipati what version of react are you both using? |
I am using |
React 16.0.0 + enzyme-adapter-react-16 1.0.1 |
I am also having this issue with |
I have tests that pass for Enzyme v2. They do the following:
Now it does not pass anymore in v3. What should I do? I'm just checking the text of the label's sibling (that is not inside any particular tag).
Console logging the parent()'s children() yields nothing while the parent() yields:
|
@nbkhope try adding |
I tried getElements(), but it returns an empty list. But I went from child to parent and the parent exists, so how can there be no children? Update: Sorry, I should have used .hostNodes(). Anyway, it yields a similar result:
So I get nothing. |
I was kind of reluctant to upgrade to v3 right away, but decided to give it a try. Now am kind of reluctant again. Anyway, I can make my tests pass using the .parents() like so:
Please fix that issue :) |
If you start with |
@ljharb that does not seem to do anything. Doing
PS: Using Enzyme v3.2.0 |
Gotcha, thanks - that seems to be the OP's issue as well. |
Seeing similar issue with enzyme@3.2.0, enzyme-adapter-react-15@1.0.5
Output:
I would expect If I replace |
This has been resolved; as the tests in #769 indicate. Please file a new issue if not. |
I am trying to get the second child element from the parent and it fails. Below is the example:
Component:
Test:
The second assertion fails with the below error message:
And when I log
parent1.children()
, I getShallowWrapper { length: 0 }
.Strangely,
expect(child12).to.be.present();
passes.The text was updated successfully, but these errors were encountered: