Deprecate ReactTestUtils.mockComponent() (#13193)

Deprecate ReactTestUtils.mockComponent()
This commit is contained in:
Brian Vaughn authored and GitHub committed 2018-07-11 10:18:49 -07:00
1 parent afd46490d0
commit d64d1ddb57
2 files changed
+13 -1

No files matched your search

+6 -1
View File
@@ -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);
+7
View File
@@ -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. ' +
'Use shallow rendering or jest.mock() instead.',
);
mockTagName = mockTagName || module.mockTagName || 'div';
module.prototype.render.mockImplementation(function() {