TestUtils.mockComponent()
has been confusing to React users because it relies on Jest-specific features, and only works when Jest module mocking is enabled. Additionally, it was broken for common patterns like functional components. For these reasons we are removing it from the React TestUtils package.
If you depend on it, you can copy and paste this drop-in replacement into your project:
function mockComponent(component, mockTagName) {
mockTagName = mockTagName || component.mockTagName || 'div';
component.prototype.render.mockImplementation(function() {
return React.createElement(mockTagName, null, this.props.children);
});
return this;
}
It is completely equivalent to what ReactTestUtils.mockComponent()
has been doing.
Check out this page for more information about mocking components.