enzymejs / enzymejs/enzyme

Cannot find descendants from .parent()

Open
#1,876 1 comment 4 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
19.8k
Forks
2k
PR merge metrics
No merged PRs in 30d

Description

### Current behavior
```javascript
describe('Parent test', () => {
it('should return a parent that can find things', () => {
class MockComponent extends React.Component {
render() {
return (


Some foo

Some bar


);
}
}

const wrapper = shallow();

// The following passes on v3
expect(wrapper.find('.foo').parents().find('.bar')).toExist();
// The following fails on v3 but passes on v2
expect(wrapper.find('.foo').parent().find('.bar')).toExist();
});
});
```

### Expected behavior

The following use case should pass:
```javascript
expect(wrapper.find('.foo').parent().find('.bar')).toExist();
```

### Your environment

#### API

- [x] shallow
- [ ] mount
- [ ] render

#### Version

| library | version
| ------------------- | -------
| enzyme | 3.7.0
| react | 16.6.0, 16.5.0
| react-dom | 16.6.0, 16.5.0
| react-test-renderer | 16.6.0, 16.5.0
| adapter (below) |

#### 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 ( )

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the provided shallow-rendering test with enzyme-adapter-react-16, focusing on the difference between parents().find('.bar') and parent().find('.bar'). Trace the traversal behavior for parent() and find(); done means the stated parent().find('.bar') assertion passes for the shown component.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.