Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate ReactTestUtils.mockComponent() #13193

Merged
merged 2 commits into from
Jul 11, 2018
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
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.',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add an fb.me link that either points to a gist or a warning page with a drop-in replacement code? People who rely on it might not understand what mockComponent was doing exactly.

);

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(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be behind a duplicate check. Otherwise it might significantly spam console in tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Sure

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow up PR #13194

false,
'ReactTestUtils.mockComponent() is deprecated. ' +
'Use shallow rendering or jest.mock() instead.',
);

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

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