From 4d5eaf596525d3359790eb0bef8bdc8a3d2a5152 Mon Sep 17 00:00:00 2001 From: Dave Brotherstone Date: Fri, 20 Nov 2015 17:57:17 +0100 Subject: [PATCH] Fix for value prop being set to zero 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 :) --- src/Select.js | 2 +- test/Select-test.js | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Select.js b/src/Select.js index 9140edd3b9..dd5178f534 100644 --- a/src/Select.js +++ b/src/Select.js @@ -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); diff --git a/test/Select-test.js b/test/Select-test.js index 356c0ac55f..ea44a4f4bb 100644 --- a/test/Select-test.js +++ b/test/Select-test.js @@ -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({