From 2fd541e0a5ad17946e84a3d9898caa4cd5fb3b54 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Wed, 11 Jul 2018 09:09:11 -0700 Subject: [PATCH 1/2] Deprecate ReactTestUtils.mockComponent() --- packages/react-dom/src/__tests__/ReactTestUtils-test.js | 7 ++++++- packages/react-dom/src/test-utils/ReactTestUtils.js | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/react-dom/src/__tests__/ReactTestUtils-test.js b/packages/react-dom/src/__tests__/ReactTestUtils-test.js index 83437133b6a6f..aed1e0aa0e609 100644 --- a/packages/react-dom/src/__tests__/ReactTestUtils-test.js +++ b/packages/react-dom/src/__tests__/ReactTestUtils-test.js @@ -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. ' + + 'We recommend using shallow rendering or jest.mock() instead.', + ); const container = document.createElement('div'); ReactDOM.render(Hello, container); diff --git a/packages/react-dom/src/test-utils/ReactTestUtils.js b/packages/react-dom/src/test-utils/ReactTestUtils.js index cc0c5a89f7f57..2e6c9189a91a4 100644 --- a/packages/react-dom/src/test-utils/ReactTestUtils.js +++ b/packages/react-dom/src/test-utils/ReactTestUtils.js @@ -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'; @@ -309,6 +310,12 @@ const ReactTestUtils = { * @return {object} the ReactTestUtils object (for chaining) */ mockComponent: function(module, mockTagName) { + lowPriorityWarning( + false, + 'ReactTestUtils.mockComponent() is deprecated. ' + + 'We recommend using shallow rendering or jest.mock() instead.', + ); + mockTagName = mockTagName || module.mockTagName || 'div'; module.prototype.render.mockImplementation(function() { From e3f3354924e5fa8dde2f3f1c2a532bbe1c8a9b1b Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Wed, 11 Jul 2018 09:44:35 -0700 Subject: [PATCH 2/2] Wording tweak --- packages/react-dom/src/__tests__/ReactTestUtils-test.js | 2 +- packages/react-dom/src/test-utils/ReactTestUtils.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/react-dom/src/__tests__/ReactTestUtils-test.js b/packages/react-dom/src/__tests__/ReactTestUtils-test.js index aed1e0aa0e609..4db78d8c11825 100644 --- a/packages/react-dom/src/__tests__/ReactTestUtils-test.js +++ b/packages/react-dom/src/__tests__/ReactTestUtils-test.js @@ -57,7 +57,7 @@ describe('ReactTestUtils', () => { ReactTestUtils.mockComponent(MockedComponent), ).toLowPriorityWarnDev( 'ReactTestUtils.mockComponent() is deprecated. ' + - 'We recommend using shallow rendering or jest.mock() instead.', + 'Use shallow rendering or jest.mock() instead.', ); const container = document.createElement('div'); diff --git a/packages/react-dom/src/test-utils/ReactTestUtils.js b/packages/react-dom/src/test-utils/ReactTestUtils.js index 2e6c9189a91a4..aba82ddc97d27 100644 --- a/packages/react-dom/src/test-utils/ReactTestUtils.js +++ b/packages/react-dom/src/test-utils/ReactTestUtils.js @@ -313,7 +313,7 @@ const ReactTestUtils = { lowPriorityWarning( false, 'ReactTestUtils.mockComponent() is deprecated. ' + - 'We recommend using shallow rendering or jest.mock() instead.', + 'Use shallow rendering or jest.mock() instead.', ); mockTagName = mockTagName || module.mockTagName || 'div';