Skip to content

Commit

Permalink
Merge pull request #226 from CurtisHumphrey/contains_bug
Browse files Browse the repository at this point in the history
[contains] Fix bug for matching sub arrays
  • Loading branch information
lelandrichardson committed Mar 7, 2016
2 parents 907fe34 + c82293c commit 43f752d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ export function nodeEqual(a, b) {

export function containsChildrenSubArray(match, node, subArray) {
const children = childrenOfNode(node);
return children.some((_, i) => arraysEqual(match, children.slice(i, subArray.length), subArray));
const checker = (_, i) => arraysEqual(match, children.slice(i, i + subArray.length), subArray);
return children.some(checker);
}

function arraysEqual(match, left, right) {
Expand Down
9 changes: 7 additions & 2 deletions test/ReactWrapper-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,18 @@ describeWithDOM('mount', () => {
<div>Goodbye</div>,
];

const passes = [
const passes1 = [
<span>Hello</span>,
<div>Goodbye</div>,
];
const passes2 = [
<div>Goodbye</div>,
<span>More</span>,
];

expect(wrapper.contains(fails)).to.equal(false);
expect(wrapper.contains(passes)).to.equal(true);
expect(wrapper.contains(passes1)).to.equal(true);
expect(wrapper.contains(passes2)).to.equal(true);
});

});
Expand Down
9 changes: 7 additions & 2 deletions test/ShallowWrapper-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,18 @@ describe('shallow', () => {
<div>Goodbye</div>,
];

const passes = [
const passes1 = [
<span>Hello</span>,
<div>Goodbye</div>,
];
const passes2 = [
<div>Goodbye</div>,
<span>More</span>,
];

expect(wrapper.contains(fails)).to.equal(false);
expect(wrapper.contains(passes)).to.equal(true);
expect(wrapper.contains(passes1)).to.equal(true);
expect(wrapper.contains(passes2)).to.equal(true);
});

});
Expand Down

0 comments on commit 43f752d

Please sign in to comment.