Skip to content

Commit

Permalink
Deprecate ReactTestUtils.mockComponent() (#13193)
Browse files Browse the repository at this point in the history
Deprecate ReactTestUtils.mockComponent()
  • Loading branch information
bvaughn authored Jul 11, 2018
1 parent afd4649 commit d64d1dd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/react-dom/src/__tests__/ReactTestUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ describe('ReactTestUtils', () => {
MockedComponent.prototype.render = jest.fn();

// Patch it up so it returns its children.
ReactTestUtils.mockComponent(MockedComponent);
expect(() =>
ReactTestUtils.mockComponent(MockedComponent),
).toLowPriorityWarnDev(
'ReactTestUtils.mockComponent() is deprecated. ' +
'Use shallow rendering or jest.mock() instead.',
);

const container = document.createElement('div');
ReactDOM.render(<MockedComponent>Hello</MockedComponent>, container);
Expand Down
7 changes: 7 additions & 0 deletions packages/react-dom/src/test-utils/ReactTestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
} from 'shared/ReactTypeOfWork';
import SyntheticEvent from 'events/SyntheticEvent';
import invariant from 'shared/invariant';
import lowPriorityWarning from 'shared/lowPriorityWarning';

import * as DOMTopLevelEventTypes from '../events/DOMTopLevelEventTypes';

Expand Down Expand Up @@ -309,6 +310,12 @@ const ReactTestUtils = {
* @return {object} the ReactTestUtils object (for chaining)
*/
mockComponent: function(module, mockTagName) {
lowPriorityWarning(
false,
'ReactTestUtils.mockComponent() is deprecated. ' +
'Use shallow rendering or jest.mock() instead.',
);

mockTagName = mockTagName || module.mockTagName || 'div';

module.prototype.render.mockImplementation(function() {
Expand Down

0 comments on commit d64d1dd

Please sign in to comment.