@samitouri / QOS-React / commits / d64d1ddb57

Deprecate ReactTestUtils.mockComponent() (#13193)

Deprecate ReactTestUtils.mockComponent()

Brian Vaughn committed Jul 11, 2018 at 10:18 UTC d64d1ddb570a4fb7d748f4c500ac083886c2f0ec
2 files changed +13 -1
packages/react-dom/src/__tests__/ReactTestUtils-test.js
+6 -1
@@ -53,7 +53,12 @@ describe('ReactTestUtils', () => {
53 MockedComponent.prototype.render = jest.fn();
54
55 // Patch it up so it returns its children.
56 - ReactTestUtils.mockComponent(MockedComponent);
56 + expect(() =>
57 + ReactTestUtils.mockComponent(MockedComponent),
58 + ).toLowPriorityWarnDev(
59 + 'ReactTestUtils.mockComponent() is deprecated. ' +
60 + 'Use shallow rendering or jest.mock() instead.',
61 + );
62
63 const container = document.createElement('div');
64 ReactDOM.render(<MockedComponent>Hello</MockedComponent>, container);
packages/react-dom/src/test-utils/ReactTestUtils.js
+7
@@ -17,6 +17,7 @@ import {
17 } from 'shared/ReactTypeOfWork';
18 import SyntheticEvent from 'events/SyntheticEvent';
19 import invariant from 'shared/invariant';
20 +import lowPriorityWarning from 'shared/lowPriorityWarning';
21
22 import * as DOMTopLevelEventTypes from '../events/DOMTopLevelEventTypes';
23
@@ -309,6 +310,12 @@ const ReactTestUtils = {
310 * @return {object} the ReactTestUtils object (for chaining)
311 */
312 mockComponent: function(module, mockTagName) {
313 + lowPriorityWarning(
314 + false,
315 + 'ReactTestUtils.mockComponent() is deprecated. ' +
316 + 'Use shallow rendering or jest.mock() instead.',
317 + );
318 +
319 mockTagName = mockTagName || module.mockTagName || 'div';
320
321 module.prototype.render.mockImplementation(function() {