mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Merge pull request #3433 from mihaip/master
Include the owner name when warning about createElement(null/undefined).
This commit is contained in:
@@ -264,7 +264,7 @@ function checkPropTypes(componentName, propTypes, props, location) {
|
||||
// same error.
|
||||
loggedTypeFailures[error.message] = true;
|
||||
|
||||
var addendum = getDeclarationErrorAddendum(this);
|
||||
var addendum = getDeclarationErrorAddendum();
|
||||
warning(false, 'Failed propType: %s%s', error.message, addendum);
|
||||
}
|
||||
}
|
||||
@@ -402,7 +402,8 @@ var ReactElementValidator = {
|
||||
type != null,
|
||||
'React.createElement: type should not be null or undefined. It should ' +
|
||||
'be a string (for DOM elements) or a ReactClass (for composite ' +
|
||||
'components).'
|
||||
'components).%s',
|
||||
getDeclarationErrorAddendum()
|
||||
);
|
||||
|
||||
var element = ReactElement.createElement.apply(this, arguments);
|
||||
|
||||
@@ -277,6 +277,27 @@ describe('ReactElementValidator', function() {
|
||||
expect(console.warn.calls.length).toBe(2);
|
||||
});
|
||||
|
||||
it('includes the owner name when passing null or undefined', function() {
|
||||
spyOn(console, 'warn');
|
||||
var ParentComp = React.createClass({
|
||||
render: function() {
|
||||
return React.createElement(null);
|
||||
}
|
||||
});
|
||||
expect(function() {
|
||||
ReactTestUtils.renderIntoDocument(React.createElement(ParentComp));
|
||||
}).toThrow();
|
||||
expect(console.warn.calls.length).toBe(2);
|
||||
expect(console.warn.calls[0].args[0]).toBe(
|
||||
'Warning: React.createElement: type should not be null or undefined. ' +
|
||||
'It should be a string (for DOM elements) or a ReactClass (for ' +
|
||||
'composite components). Check the render method of `ParentComp`.'
|
||||
);
|
||||
expect(console.warn.calls[1].args[0]).toBe(
|
||||
'Warning: Only functions or strings can be mounted as React components.'
|
||||
);
|
||||
});
|
||||
|
||||
it('should check default prop values', function() {
|
||||
spyOn(console, 'warn');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user