Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/test/ReactTestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,22 @@ assign(
);

ReactShallowRenderer.prototype.render = function(element, context) {
invariant(
ReactElement.isValidElement(element),
'ReactShallowRenderer render(): Invalid component element.%s',
typeof element === 'function' ?
' Instead of passing a component class, make sure to instantiate ' +
'it by passing it to React.createElement.' :
''
);
invariant(
typeof element.type !== 'string',
'ReactShallowRenderer render(): Shallow rendering works only with custom ' +
'components, not primitives (%s). Instead of calling `.render(el)` and ' +
'inspecting the rendered output, look at `el.props` directly instead.',
element.type
);

if (!context) {
context = emptyObject;
}
Expand Down
21 changes: 21 additions & 0 deletions src/test/__tests__/ReactTestUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,27 @@ describe('ReactTestUtils', function() {
]);
});

it('should throw for invalid elements', function() {
var SomeComponent = React.createClass({
render: function() {
return <div />;
},
});

var shallowRenderer = ReactTestUtils.createRenderer();
expect(() => shallowRenderer.render(SomeComponent)).toThrow(
'Invariant Violation: ReactShallowRenderer render(): Invalid component ' +
'element. Instead of passing a component class, make sure to ' +
'instantiate it by passing it to React.createElement.'
);
expect(() => shallowRenderer.render(<div />)).toThrow(
'Invariant Violation: ReactShallowRenderer render(): Shallow rendering ' +
'works only with custom components, not primitives (div). Instead of ' +
'calling `.render(el)` and inspecting the rendered output, look at ' +
'`el.props` directly instead.'
);
});

it('should have shallow unmounting', function() {
var componentWillUnmount = mocks.getMockFunction();

Expand Down