Skip to content

Commit

Permalink
[changed] Use PropTypes.node for validation and fix/add tests
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jontewks committed Sep 3, 2015
1 parent d679b2b commit bad277e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/utils/childrenValueInputValidation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
6 changes: 1 addition & 5 deletions test/ButtonInputSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ describe('ButtonInput', () =>{
ReactTestUtils.renderIntoDocument(
<ButtonInput value="button" bsStyle="danger" />
);

console.warn.called.should.be.false;
});

it('throws warning about wrong type for bsStyle=error', function () {
Expand Down Expand Up @@ -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(
<ButtonInput><span>blah</span></ButtonInput>
);

shouldWarn('propType: Invalid');
});
});
6 changes: 6 additions & 0 deletions test/FormControlsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,11 @@ describe('Form Controls', function () {

result.should.be.instanceOf(Error);
});

it('allows elements as children', function () {
ReactTestUtils.renderIntoDocument(
<FormControls.Static><span>blah</span></FormControls.Static>
);
});
});
});

0 comments on commit bad277e

Please sign in to comment.