Merge pull request #3293 from spicyj/gh-3286

ReactFragment counts as a node without warning
This commit is contained in:
Sebastian Markbåge 2015-03-02 12:10:50 -08:00
commit edddd57d28
3 changed files with 22 additions and 2 deletions

View File

@ -141,7 +141,8 @@ var ReactFragment = {
warning(
didWarnForFragment(fragment),
'Any use of a keyed object should be wrapped in ' +
'React.addons.createFragment(object) before passed as a child.'
'React.addons.createFragment(object) before being passed as a ' +
'child.'
);
return fragment;
}

View File

@ -12,6 +12,7 @@
'use strict';
var ReactElement = require('ReactElement');
var ReactFragment = require('ReactFragment');
var ReactPropTypeLocationNames = require('ReactPropTypeLocationNames');
var emptyFunction = require('emptyFunction');
@ -301,6 +302,7 @@ function isNode(propValue) {
if (ReactElement.isValidElement(propValue)) {
return true;
}
propValue = ReactFragment.extractIfFragment(propValue);
for (var k in propValue) {
if (!isNode(propValue[k])) {
return false;

View File

@ -13,6 +13,7 @@
var PropTypes;
var React;
var ReactFragment;
var ReactPropTypeLocations;
var ReactTestUtils;
@ -48,6 +49,7 @@ describe('ReactPropTypes', function() {
beforeEach(function() {
PropTypes = require('ReactPropTypes');
React = require('React');
ReactFragment = require('ReactFragment');
ReactPropTypeLocations = require('ReactPropTypeLocations');
ReactTestUtils = require('ReactTestUtils');
});
@ -356,6 +358,7 @@ describe('ReactPropTypes', function() {
});
it('should not warn for valid values', function() {
spyOn(console, 'warn');
typeCheckPass(PropTypes.node, <div />);
typeCheckPass(PropTypes.node, false);
typeCheckPass(PropTypes.node, <MyComponent />);
@ -371,7 +374,21 @@ describe('ReactPropTypes', function() {
<MyComponent />
]);
// Object of rendereable things
// Object of renderable things
var frag = ReactFragment.create;
typeCheckPass(PropTypes.node, frag({
k0: 123,
k1: 'Some string',
k2: <div />,
k3: frag({
k30: <MyComponent />,
k31: frag({k310: <a />}),
k32: 'Another string'
})
}));
expect(console.warn.calls).toEqual([]);
// This should also pass, though it warns
typeCheckPass(PropTypes.node, {
k0: 123,
k1: 'Some string',