Skip to content

Commit 616c80c

Browse files
committed
add parent tests
1 parent 0f9d9e0 commit 616c80c

2 files changed

Lines changed: 92 additions & 0 deletions

File tree

packages/enzyme-test-suite/test/ReactWrapper-spec.jsx

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3893,6 +3893,52 @@ describeWithDOM('mount', () => {
38933893
const formUp = input.parents('form');
38943894
expect(formUp).to.have.lengthOf(1);
38953895
});
3896+
3897+
it('works when called sequentially on two sibling nodes', () => {
3898+
class Test extends React.Component {
3899+
render() {
3900+
return (
3901+
<div>
3902+
<div className="a">
3903+
<div>A child</div>
3904+
</div>
3905+
<div className="b">
3906+
<div>B child</div>
3907+
</div>
3908+
</div>
3909+
);
3910+
}
3911+
}
3912+
const wrapper = mount(<Test />);
3913+
const aChild = wrapper.find({ children: 'A child' });
3914+
expect(aChild.debug()).to.equal(`<div>
3915+
A child
3916+
</div>`);
3917+
expect(aChild).to.have.lengthOf(1);
3918+
const bChild = wrapper.find({ children: 'B child' });
3919+
expect(bChild.debug()).to.equal(`<div>
3920+
B child
3921+
</div>`);
3922+
expect(bChild).to.have.lengthOf(1);
3923+
3924+
wrapper.update();
3925+
3926+
const bChildParents = bChild.parents('.b');
3927+
expect(bChildParents.debug()).to.equal(`<div className="b">
3928+
<div>
3929+
B child
3930+
</div>
3931+
</div>`);
3932+
expect(bChildParents).to.have.lengthOf(1);
3933+
3934+
const aChildParents = aChild.parents('.a');
3935+
expect(aChildParents.debug()).to.equal(`<div className="a">
3936+
<div>
3937+
A child
3938+
</div>
3939+
</div>`);
3940+
expect(aChildParents).to.have.lengthOf(1);
3941+
});
38963942
});
38973943

38983944
describe('.parent()', () => {

packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3556,6 +3556,52 @@ describe('shallow', () => {
35563556
expect(parents.at(0).hasClass('foo')).to.equal(true);
35573557
expect(parents.at(1).hasClass('bax')).to.equal(true);
35583558
});
3559+
3560+
it('works when called sequentially on two sibling nodes', () => {
3561+
class Test extends React.Component {
3562+
render() {
3563+
return (
3564+
<div>
3565+
<div className="a">
3566+
<div>A child</div>
3567+
</div>
3568+
<div className="b">
3569+
<div>B child</div>
3570+
</div>
3571+
</div>
3572+
);
3573+
}
3574+
}
3575+
const wrapper = shallow(<Test />);
3576+
const aChild = wrapper.find({ children: 'A child' });
3577+
expect(aChild.debug()).to.equal(`<div>
3578+
A child
3579+
</div>`);
3580+
expect(aChild).to.have.lengthOf(1);
3581+
const bChild = wrapper.find({ children: 'B child' });
3582+
expect(bChild.debug()).to.equal(`<div>
3583+
B child
3584+
</div>`);
3585+
expect(bChild).to.have.lengthOf(1);
3586+
3587+
wrapper.update();
3588+
3589+
const bChildParents = bChild.parents('.b');
3590+
expect(bChildParents.debug()).to.equal(`<div className="b">
3591+
<div>
3592+
B child
3593+
</div>
3594+
</div>`);
3595+
expect(bChildParents).to.have.lengthOf(1);
3596+
3597+
const aChildParents = aChild.parents('.a');
3598+
expect(aChildParents.debug()).to.equal(`<div className="a">
3599+
<div>
3600+
A child
3601+
</div>
3602+
</div>`);
3603+
expect(aChildParents).to.have.lengthOf(1);
3604+
});
35593605
});
35603606

35613607
describe('.parent()', () => {

0 commit comments

Comments
 (0)