warn for using maps as children with owner info (#7260)

(cherry picked from commit 5103e1d6a1)
This commit is contained in:
Keyan Zhang
2016-07-13 11:44:10 -07:00
committed by Paul O’Shannessy
parent 1c3b4af564
commit 615ae2f497
2 changed files with 32 additions and 1 deletions
@@ -15,11 +15,14 @@ describe('traverseAllChildren', function() {
var traverseAllChildren;
var React;
var ReactFragment;
var ReactTestUtils;
beforeEach(function() {
jest.resetModuleRegistry();
traverseAllChildren = require('traverseAllChildren');
React = require('React');
ReactFragment = require('ReactFragment');
ReactTestUtils = require('ReactTestUtils');
});
function frag(obj) {
@@ -536,4 +539,24 @@ describe('traverseAllChildren', function() {
);
});
it('should warn for using maps as children with owner info', function() {
spyOn(console, 'error');
var Parent = React.createClass({
render() {
return (
<div>{new Map([['foo', 0], ['bar', 1]])}</div>
);
},
});
ReactTestUtils.renderIntoDocument(<Parent />);
expect(console.error.calls.count()).toBe(1);
expect(console.error.calls.argsFor(0)[0]).toBe(
'Warning: Using Maps as children is not yet fully supported. It is an ' +
'experimental feature that might be removed. Convert it to a sequence ' +
'/ iterable of keyed ReactElements instead. Check the render method of `Parent`.'
);
});
});
+9 -1
View File
@@ -117,11 +117,19 @@ function traverseAllChildrenImpl(
}
} else {
if (__DEV__) {
var mapsAsChildrenAddendum = '';
if (ReactCurrentOwner.current) {
var mapsAsChildrenOwnerName = ReactCurrentOwner.current.getName();
if (mapsAsChildrenOwnerName) {
mapsAsChildrenAddendum = ' Check the render method of `' + mapsAsChildrenOwnerName + '`.';
}
}
warning(
didWarnAboutMaps,
'Using Maps as children is not yet fully supported. It is an ' +
'experimental feature that might be removed. Convert it to a ' +
'sequence / iterable of keyed ReactElements instead.'
'sequence / iterable of keyed ReactElements instead.%s',
mapsAsChildrenAddendum
);
didWarnAboutMaps = true;
}