From bad277e6b3e7b382fdea59b84bd71f1cb05594c4 Mon Sep 17 00:00:00 2001 From: Jon Tewksbury Date: Wed, 2 Sep 2015 23:22:40 -0700 Subject: [PATCH] [changed] Use PropTypes.node for validation and fix/add tests Previously the ButtonInput and FormControls.Static were using a PropType check of either number or string. This change moves the check to node so that you can pass in elements as well as numbers and strings. --- src/utils/childrenValueInputValidation.js | 6 +++--- test/ButtonInputSpec.js | 6 +----- test/FormControlsSpec.js | 6 ++++++ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/utils/childrenValueInputValidation.js b/src/utils/childrenValueInputValidation.js index 075a4c42b0..ac8af1520a 100644 --- a/src/utils/childrenValueInputValidation.js +++ b/src/utils/childrenValueInputValidation.js @@ -2,13 +2,13 @@ import React from 'react'; import { singlePropFrom } from './CustomPropTypes'; const propList = ['children', 'value']; -const typeList = [React.PropTypes.number, React.PropTypes.string]; export default function valueValidation(props, propName, componentName) { let error = singlePropFrom(propList)(props, propName, componentName); + if (!error) { - const oneOfType = React.PropTypes.oneOfType(typeList); - error = oneOfType(props, propName, componentName); + error = React.PropTypes.node(props, propName, componentName); } + return error; } diff --git a/test/ButtonInputSpec.js b/test/ButtonInputSpec.js index d196632bfc..f2934fd79c 100644 --- a/test/ButtonInputSpec.js +++ b/test/ButtonInputSpec.js @@ -42,8 +42,6 @@ describe('ButtonInput', () =>{ ReactTestUtils.renderIntoDocument( ); - - console.warn.called.should.be.false; }); it('throws warning about wrong type for bsStyle=error', function () { @@ -72,11 +70,9 @@ describe('ButtonInput', () =>{ assert.notInstanceOf(result, Error); }); - it('does not allow elements for children', function () { + it('allows elements as children', function () { ReactTestUtils.renderIntoDocument( blah ); - - shouldWarn('propType: Invalid'); }); }); diff --git a/test/FormControlsSpec.js b/test/FormControlsSpec.js index 31c9941d30..962e0d5433 100644 --- a/test/FormControlsSpec.js +++ b/test/FormControlsSpec.js @@ -33,5 +33,11 @@ describe('Form Controls', function () { result.should.be.instanceOf(Error); }); + + it('allows elements as children', function () { + ReactTestUtils.renderIntoDocument( + blah + ); + }); }); });