From b2f77e6de31c71999a8d294a9bb742643c936b01 Mon Sep 17 00:00:00 2001 From: Jim Date: Tue, 27 Jan 2015 10:14:09 -0800 Subject: [PATCH] Add detectable prefix to ReactElement proptype warning. --- src/classic/element/ReactElementValidator.js | 2 +- .../__tests__/ReactElementValidator-test.js | 15 ++++++++++----- .../types/__tests__/ReactPropTypes-test.js | 3 ++- .../__tests__/ReactJSXElementValidator-test.js | 15 ++++++++++----- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/classic/element/ReactElementValidator.js b/src/classic/element/ReactElementValidator.js index 06b9fc2b5c..cefc9899b2 100644 --- a/src/classic/element/ReactElementValidator.js +++ b/src/classic/element/ReactElementValidator.js @@ -269,7 +269,7 @@ function checkPropTypes(componentName, propTypes, props, location) { loggedTypeFailures[error.message] = true; var addendum = getDeclarationErrorAddendum(this); - warning(false, error.message + addendum); + warning(false, 'Failed propType: ' + error.message + addendum); } } } diff --git a/src/classic/element/__tests__/ReactElementValidator-test.js b/src/classic/element/__tests__/ReactElementValidator-test.js index 311be0377b..130b8d1eea 100644 --- a/src/classic/element/__tests__/ReactElementValidator-test.js +++ b/src/classic/element/__tests__/ReactElementValidator-test.js @@ -206,7 +206,8 @@ describe('ReactElementValidator', function() { }); ReactTestUtils.renderIntoDocument(React.createElement(ParentComp)); expect(console.warn.calls[0].args[0]).toBe( - 'Warning: Invalid prop `color` of type `number` supplied to `MyComp`, ' + + 'Warning: Failed propType: ' + + 'Invalid prop `color` of type `number` supplied to `MyComp`, ' + 'expected `string`. Check the render method of `ParentComp`.' ); }); @@ -247,7 +248,8 @@ describe('ReactElementValidator', function() { expect(console.warn.calls.length).toBe(1); expect(console.warn.calls[0].args[0]).toBe( - 'Warning: Required prop `prop` was not specified in `Component`.' + 'Warning: Failed propType: ' + + 'Required prop `prop` was not specified in `Component`.' ); }); @@ -270,7 +272,8 @@ describe('ReactElementValidator', function() { expect(console.warn.calls.length).toBe(1); expect(console.warn.calls[0].args[0]).toBe( - 'Warning: Required prop `prop` was not specified in `Component`.' + 'Warning: Failed propType: ' + + 'Required prop `prop` was not specified in `Component`.' ); }); @@ -295,11 +298,13 @@ describe('ReactElementValidator', function() { expect(console.warn.calls.length).toBe(2); expect(console.warn.calls[0].args[0]).toBe( - 'Warning: Required prop `prop` was not specified in `Component`.' + 'Warning: Failed propType: ' + + 'Required prop `prop` was not specified in `Component`.' ); expect(console.warn.calls[1].args[0]).toBe( - 'Warning: Invalid prop `prop` of type `number` supplied to ' + + 'Warning: Failed propType: ' + + 'Invalid prop `prop` of type `number` supplied to ' + '`Component`, expected `string`.' ); diff --git a/src/classic/types/__tests__/ReactPropTypes-test.js b/src/classic/types/__tests__/ReactPropTypes-test.js index fe0ad4a340..0c0ee7d189 100644 --- a/src/classic/types/__tests__/ReactPropTypes-test.js +++ b/src/classic/types/__tests__/ReactPropTypes-test.js @@ -752,7 +752,8 @@ describe('ReactPropTypes', function() { var instance = ; instance = ReactTestUtils.renderIntoDocument(instance); expect(console.warn.argsForCall.length).toBe(1); - expect(console.warn.argsForCall[0][0]).toBe('Warning: num must be 5!'); + expect(console.warn.argsForCall[0][0]).toBe( + 'Warning: Failed propType: num must be 5!'); }); it('should not warn if the validator returned anything else than an error', diff --git a/src/modern/element/__tests__/ReactJSXElementValidator-test.js b/src/modern/element/__tests__/ReactJSXElementValidator-test.js index 5ed0823dc7..3bb211aec8 100644 --- a/src/modern/element/__tests__/ReactJSXElementValidator-test.js +++ b/src/modern/element/__tests__/ReactJSXElementValidator-test.js @@ -196,7 +196,8 @@ describe('ReactJSXElementValidator', function() { } ReactTestUtils.renderIntoDocument(); expect(console.warn.calls[0].args[0]).toBe( - 'Warning: Invalid prop `color` of type `number` supplied to `MyComp`, ' + + 'Warning: Failed propType: ' + + 'Invalid prop `color` of type `number` supplied to `MyComp`, ' + 'expected `string`. Check the render method of `ParentComp`.' ); }); @@ -236,7 +237,8 @@ describe('ReactJSXElementValidator', function() { expect(console.warn.calls.length).toBe(1); expect(console.warn.calls[0].args[0]).toBe( - 'Warning: Required prop `prop` was not specified in `Component`.' + 'Warning: Failed propType: ' + + 'Required prop `prop` was not specified in `Component`.' ); }); @@ -255,7 +257,8 @@ describe('ReactJSXElementValidator', function() { expect(console.warn.calls.length).toBe(1); expect(console.warn.calls[0].args[0]).toBe( - 'Warning: Required prop `prop` was not specified in `Component`.' + 'Warning: Failed propType: ' + + 'Required prop `prop` was not specified in `Component`.' ); }); @@ -276,11 +279,13 @@ describe('ReactJSXElementValidator', function() { expect(console.warn.calls.length).toBe(2); expect(console.warn.calls[0].args[0]).toBe( - 'Warning: Required prop `prop` was not specified in `Component`.' + 'Warning: Failed propType: ' + + 'Required prop `prop` was not specified in `Component`.' ); expect(console.warn.calls[1].args[0]).toBe( - 'Warning: Invalid prop `prop` of type `number` supplied to ' + + 'Warning: Failed propType: ' + + 'Invalid prop `prop` of type `number` supplied to ' + '`Component`, expected `string`.' );