File tree 2 files changed +37
-0
lines changed 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -396,6 +396,22 @@ assign(
396
396
) ;
397
397
398
398
ReactShallowRenderer . prototype . render = function ( element , context ) {
399
+ invariant (
400
+ ReactElement . isValidElement ( element ) ,
401
+ 'ReactShallowRenderer render(): Invalid component element.%s' ,
402
+ typeof element === 'function' ?
403
+ ' Instead of passing a component class, make sure to instantiate ' +
404
+ 'it by passing it to React.createElement.' :
405
+ ''
406
+ ) ;
407
+ invariant (
408
+ typeof element . type !== 'string' ,
409
+ 'ReactShallowRenderer render(): Shallow rendering works only with custom ' +
410
+ 'components, not primitives (%s). Instead of calling `.render(el)` and ' +
411
+ 'inspecting the rendered output, look at `el.props` directly instead.' ,
412
+ element . type
413
+ ) ;
414
+
399
415
if ( ! context ) {
400
416
context = emptyObject ;
401
417
}
Original file line number Diff line number Diff line change @@ -53,6 +53,27 @@ describe('ReactTestUtils', function() {
53
53
] ) ;
54
54
} ) ;
55
55
56
+ it ( 'should throw for invalid elements' , function ( ) {
57
+ var SomeComponent = React . createClass ( {
58
+ render : function ( ) {
59
+ return < div /> ;
60
+ } ,
61
+ } ) ;
62
+
63
+ var shallowRenderer = ReactTestUtils . createRenderer ( ) ;
64
+ expect ( ( ) => shallowRenderer . render ( SomeComponent ) ) . toThrow (
65
+ 'Invariant Violation: ReactShallowRenderer render(): Invalid component ' +
66
+ 'element. Instead of passing a component class, make sure to ' +
67
+ 'instantiate it by passing it to React.createElement.'
68
+ ) ;
69
+ expect ( ( ) => shallowRenderer . render ( < div /> ) ) . toThrow (
70
+ 'Invariant Violation: ReactShallowRenderer render(): Shallow rendering ' +
71
+ 'works only with custom components, not primitives (div). Instead of ' +
72
+ 'calling `.render(el)` and inspecting the rendered output, look at ' +
73
+ '`el.props` directly instead.'
74
+ ) ;
75
+ } ) ;
76
+
56
77
it ( 'should have shallow unmounting' , function ( ) {
57
78
var componentWillUnmount = mocks . getMockFunction ( ) ;
58
79
You can’t perform that action at this time.
0 commit comments