Skip to content

Commit

Permalink
Fix for value prop being set to zero
Browse files Browse the repository at this point in the history
The test for a single value of 0 was already there, and it caught the bug for the simple 
test of `if (!value) ...`.  Yay for tests :)
  • Loading branch information
bruderstein committed Nov 20, 2015
1 parent ad2ad88 commit 4d5eaf5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ const Select = React.createClass({
if (this.props.multi) {
if (typeof value === 'string') value = value.split(this.props.delimiter);
if (!Array.isArray(value)) {
if (!value) return [];
if (value === null || value === undefined) return [];
value = [value];
}
return value.map(this.expandValue).filter(i => i);
Expand Down
14 changes: 13 additions & 1 deletion test/Select-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,19 @@ describe('Select', () => {
]);
});

it('supports updating the value to 0', () => {
it('supports updating the value to a single value', () => {

wrapper.setPropsForChild({
value: 1
});

expect(ReactDOM.findDOMNode(instance), 'queried for', '.Select-value .Select-value-label',
'to satisfy', [
expect.it('to have text', 'One')
]);
});

it('supports updating the value to single value of 0', () => {

// This test is specifically in case there's a "if (value) {... " somewhere
wrapper.setPropsForChild({
Expand Down

0 comments on commit 4d5eaf5

Please sign in to comment.