diff --git a/src/test/ReactTestUtils.js b/src/test/ReactTestUtils.js index 64b39fe5e3403..f400becc5f4ad 100644 --- a/src/test/ReactTestUtils.js +++ b/src/test/ReactTestUtils.js @@ -470,6 +470,11 @@ ReactShallowRenderer.prototype._render = function(element, transaction, context) function makeSimulator(eventType) { return function(domComponentOrNode, eventData) { var node; + invariant( + !React.isValidElement(domComponentOrNode), + 'TestUtils.Simulate expects a component instance and not a ReactElement.' + + 'TestUtils.Simulate will not work if you are using shallow rendering.' + ); if (ReactTestUtils.isDOMComponent(domComponentOrNode)) { node = findDOMNode(domComponentOrNode); } else if (domComponentOrNode.tagName) { diff --git a/src/test/__tests__/ReactTestUtils-test.js b/src/test/__tests__/ReactTestUtils-test.js index 00a6b5c0ce172..57f20971707a9 100644 --- a/src/test/__tests__/ReactTestUtils-test.js +++ b/src/test/__tests__/ReactTestUtils-test.js @@ -421,6 +421,27 @@ describe('ReactTestUtils', function() { expect(handler).toHaveBeenCalledWith(jasmine.objectContaining({target: node})); }); + it('should throw when attempting to use ReactTestUtils.Simulate with shallow rendering', function() { + var SomeComponent = React.createClass({ + render: function() { + return ( +