Deprecate test utils mock component follow up (#13194)

* De-duplicate the mockComponent deprecation warning

* Added fb.me link to mockComponent
This commit is contained in:
Brian Vaughn
2018-07-11 11:56:44 -07:00
committed by GitHub
parent 6ebc8f3c07
commit 7b99ceabec
2 changed files with 16 additions and 6 deletions
+5 -1
View File
@@ -57,9 +57,13 @@ describe('ReactTestUtils', () => {
ReactTestUtils.mockComponent(MockedComponent),
).toLowPriorityWarnDev(
'ReactTestUtils.mockComponent() is deprecated. ' +
'Use shallow rendering or jest.mock() instead.',
'Use shallow rendering or jest.mock() instead.\n\n' +
'See https://fb.me/test-utils-mock-component for more information.',
);
// De-duplication check
ReactTestUtils.mockComponent(MockedComponent);
const container = document.createElement('div');
ReactDOM.render(<MockedComponent>Hello</MockedComponent>, container);
expect(container.textContent).toBe('Hello');
+11 -5
View File
@@ -33,6 +33,8 @@ const {
function Event(suffix) {}
let hasWarnedAboutDeprecatedMockComponent = false;
/**
* @class ReactTestUtils
*/
@@ -310,11 +312,15 @@ 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.',
);
if (!hasWarnedAboutDeprecatedMockComponent) {
hasWarnedAboutDeprecatedMockComponent = true;
lowPriorityWarning(
false,
'ReactTestUtils.mockComponent() is deprecated. ' +
'Use shallow rendering or jest.mock() instead.\n\n' +
'See https://fb.me/test-utils-mock-component for more information.',
);
}
mockTagName = mockTagName || module.mockTagName || 'div';