Skip to content
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

Changed tests to highlight a bug with contains, fixed the bug in Utils/containsChildrenSubArray #226

Merged
merged 1 commit into from
Mar 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,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>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you include both tests (with both orderings, i mean) to ensure we don't regress in the future?

];

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