Skip to content

Commit

Permalink
Merge pull request #769 from just-boris/master
Browse files Browse the repository at this point in the history
Add tests on broken .parent() use-case.

Closes #410.
  • Loading branch information
ljharb authored Jul 6, 2018
2 parents ce1e113 + d4b2379 commit aa52bc2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
21 changes: 21 additions & 0 deletions packages/enzyme-test-suite/test/ReactWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2422,6 +2422,27 @@ describeWithDOM('mount', () => {
expect(parents.at(0).hasClass('foo')).to.equal(true);
expect(parents.at(1).hasClass('bax')).to.equal(true);
});

it('should work with components in the tree', () => {
const Foo = createClass({
render() {
return <div className="bar" />;
},
});
const wrapper = mount((
<div className="root">
<Foo />
</div>
));
const root = wrapper.find('.root');
expect(root).to.have.lengthOf(1);
expect(root.hasClass('root')).to.equal(true);
expect(root.hasClass('bar')).to.equal(false);

const bar = root.find('.bar');
expect(bar).to.have.lengthOf(1);
expect(bar.parents('.root')).to.have.lengthOf(1);
});
});

describe('.parent()', () => {
Expand Down
11 changes: 11 additions & 0 deletions packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2282,6 +2282,17 @@ describe('shallow', () => {
expect(parents.at(1).hasClass('bar')).to.equal(true);
expect(parents.at(2).hasClass('bax')).to.equal(true);
});

it('should work with component', () => {
const Foo = createClass({
render() {
return <div className="bar" />;
},
});
const wrapper = shallow(<Foo />);
expect(wrapper.find('.bar')).to.have.length(1);
expect(wrapper.find('.bar').parent()).to.have.length(0);
});
});

describe('.closest(selector)', () => {
Expand Down

0 comments on commit aa52bc2

Please sign in to comment.