Skip to content

Commit

Permalink
[Fix] zero is a falsy but valid propValue.
Browse files Browse the repository at this point in the history
Fixes #562.
  • Loading branch information
ljharb committed Aug 26, 2016
1 parent e5cb263 commit f76bc53
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/MountedTraversal.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export function instHasProperty(inst, propKey, stringifiedPropValue) {
return false;
}

if (propValue) {
if (propValue || propValue === 0) {
return nodePropValue === propValue;
}

Expand Down
2 changes: 1 addition & 1 deletion src/ShallowTraversal.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export function nodeHasProperty(node, propKey, stringifiedPropValue) {
return false;
}

if (propValue) {
if (propValue || propValue === 0) {
return nodePropValue === propValue;
}

Expand Down
4 changes: 4 additions & 0 deletions test/ShallowTraversal-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ describe('ShallowTraversal', () => {
expect(nodeHasProperty(<div foo={2e8} />, 'foo', '2e8')).to.equal(true);
expect(nodeHasProperty(<div foo={Infinity} />, 'foo', 'Infinity')).to.equal(true);
expect(nodeHasProperty(<div foo={-Infinity} />, 'foo', '-Infinity')).to.equal(true);
expect(nodeHasProperty(<div foo={0} />, 'foo', '0')).to.equal(true);
expect(nodeHasProperty(<div foo={-0} />, 'foo', '-0')).to.equal(true);
expect(nodeHasProperty(<div foo={1} />, 'foo', '0')).to.equal(false);
expect(nodeHasProperty(<div foo={2} />, 'foo', '-0')).to.equal(false);
});

it('should throw when un unquoted string is passed in', () => {
Expand Down

0 comments on commit f76bc53

Please sign in to comment.