@samitouri / QOS-React-2 / commits / 60a101eced

Include the owner name when warning about createElement(null/undefined).

Makes it easier to find the callsite that needs to be fixed.

Mihai Parparita committed Mar 16, 2015 at 22:05 UTC 60a101ecedf1826f3ac8cace16887555e326284d
2 files changed +24 -2
src/classic/element/ReactElementValidator.js
+3 -2
@@ -264,7 +264,7 @@ function checkPropTypes(componentName, propTypes, props, location) {
264 // same error.
265 loggedTypeFailures[error.message] = true;
266
267 - var addendum = getDeclarationErrorAddendum(this);
267 + var addendum = getDeclarationErrorAddendum();
268 warning(false, 'Failed propType: %s%s', error.message, addendum);
269 }
270 }
@@ -402,7 +402,8 @@ var ReactElementValidator = {
402 type != null,
403 'React.createElement: type should not be null or undefined. It should ' +
404 'be a string (for DOM elements) or a ReactClass (for composite ' +
405 - 'components).'
405 + 'components).%s',
406 + getDeclarationErrorAddendum()
407 );
408
409 var element = ReactElement.createElement.apply(this, arguments);
src/classic/element/__tests__/ReactElementValidator-test.js
+21
@@ -277,6 +277,27 @@ describe('ReactElementValidator', function() {
277 expect(console.warn.calls.length).toBe(2);
278 });
279
280 + it('includes the owner name when passing null or undefined', function() {
281 + spyOn(console, 'warn');
282 + var ParentComp = React.createClass({
283 + render: function() {
284 + return React.createElement(null);
285 + }
286 + });
287 + expect(function() {
288 + ReactTestUtils.renderIntoDocument(React.createElement(ParentComp));
289 + }).toThrow();
290 + expect(console.warn.calls.length).toBe(2);
291 + expect(console.warn.calls[0].args[0]).toBe(
292 + 'Warning: React.createElement: type should not be null or undefined. ' +
293 + 'It should be a string (for DOM elements) or a ReactClass (for ' +
294 + 'composite components). Check the render method of `ParentComp`.'
295 + );
296 + expect(console.warn.calls[1].args[0]).toBe(
297 + 'Warning: Only functions or strings can be mounted as React components.'
298 + );
299 + });
300 +
301 it('should check default prop values', function() {
302 spyOn(console, 'warn');
303