Skip to content

Commit

Permalink
equals should skip null and undefined nodes fix #151
Browse files Browse the repository at this point in the history
  • Loading branch information
smacker committed Feb 16, 2016
1 parent dd655c4 commit 4909c4f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ export function nodeEqual(a, b) {
const right = propsOfNode(b);
for (let i = 0; i < leftKeys.length; i++) {
const prop = leftKeys[i];
if (!(prop in right)) return false;
if (prop === 'children') {
if (!childrenEqual(childrenToArray(left.children), childrenToArray(right.children))) {
return false;
}
return childrenEqual(childrenToArray(left.children), childrenToArray(right.children));
}

if (!(prop in right)) {
return false;
} else if (right[prop] === left[prop]) {
// continue;
} else if (typeof right[prop] === typeof left[prop] && typeof left[prop] === 'object') {
Expand Down
28 changes: 28 additions & 0 deletions test/Utils-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,34 @@ describe('Utils', () => {

});

it('should skip null children', () => {
expect(nodeEqual(
<div>{null}</div>,
<div></div>
)).to.equal(true);
});

it('should skip undefined children', () => {
expect(nodeEqual(
<div>{undefined}</div>,
<div></div>
)).to.equal(true);
});

it('should skip empty children', () => {
expect(nodeEqual(
<div>{[]}</div>,
<div></div>
)).to.equal(true);
});

it('should skip array of null children', () => {
expect(nodeEqual(
<div>{[null, null, null]}</div>,
<div></div>
)).to.equal(true);
});

});

describe('propFromEvent', () => {
Expand Down

0 comments on commit 4909c4f

Please sign in to comment.