diff --git a/scripts/fiber/tests-passing.txt b/scripts/fiber/tests-passing.txt index fb94519a931b6..e5fd7165a90f0 100644 --- a/scripts/fiber/tests-passing.txt +++ b/scripts/fiber/tests-passing.txt @@ -1972,6 +1972,9 @@ src/renderers/dom/test/__tests__/ReactTestUtils-test.js * should enable rendering of cloned element * should set the type of the event * should work with renderIntoDocument +* should log a deprecation warning if ReactTestUtils.isCompositeComponentElement is invoked +* should log a deprecation warning if ReactTestUtils.isCompositeComponentElementWithType is invoked +* should log a deprecation warning if ReactTestUtils.getRenderedChildOfCompositeComponent is invoked src/renderers/native/__tests__/ReactNativeAttributePayload-test.js * should work with simple example diff --git a/src/renderers/dom/test/ReactTestUtilsEntry.js b/src/renderers/dom/test/ReactTestUtilsEntry.js index a08eef557cb88..0f04b0baf876a 100644 --- a/src/renderers/dom/test/ReactTestUtilsEntry.js +++ b/src/renderers/dom/test/ReactTestUtilsEntry.js @@ -19,6 +19,7 @@ var ReactInstanceMap = require('ReactInstanceMap'); var ReactShallowRenderer = require('ReactShallowRendererEntry'); // TODO (bvaughn) Remove this import before 16.0.0 var ReactTypeOfWork = require('ReactTypeOfWork'); var SyntheticEvent = require('SyntheticEvent'); +var lowPriorityWarning = require('lowPriorityWarning'); var invariant = require('fbjs/lib/invariant'); var warning = require('fbjs/lib/warning'); @@ -194,7 +195,6 @@ var ReactTestUtils = { return constructor === type; }, - // TODO: deprecate? It's undocumented and unused. isCompositeComponentElement: function(inst) { if (!React.isValidElement(inst)) { return false; @@ -208,7 +208,6 @@ var ReactTestUtils = { ); }, - // TODO: deprecate? It's undocumented and unused. isCompositeComponentElementWithType: function(inst, type) { var internalInstance = ReactInstanceMap.get(inst); var constructor = internalInstance._currentElement.type; @@ -217,7 +216,6 @@ var ReactTestUtils = { constructor === type); }, - // TODO: deprecate? It's undocumented and unused. getRenderedChildOfCompositeComponent: function(inst) { if (!ReactTestUtils.isCompositeComponent(inst)) { return null; @@ -570,4 +568,19 @@ Object.keys(topLevelTypes).forEach(function(eventType) { ); }); +[ + 'isCompositeComponentElement', + 'isCompositeComponentElementWithType', + 'getRenderedChildOfCompositeComponent', +].forEach(fnName => { + var fn = ReactTestUtils[fnName]; + ReactTestUtils[fnName] = function(...args) { + lowPriorityWarning( + false, + `ReactTestUtils.${fnName} is deprecated as of React v15.6.2.`, + ); + return fn(...args); + }; +}); + module.exports = ReactTestUtils; diff --git a/src/renderers/dom/test/__tests__/ReactTestUtils-test.js b/src/renderers/dom/test/__tests__/ReactTestUtils-test.js index 624bc9c9fed7a..f2548848ba8c5 100644 --- a/src/renderers/dom/test/__tests__/ReactTestUtils-test.js +++ b/src/renderers/dom/test/__tests__/ReactTestUtils-test.js @@ -843,5 +843,26 @@ describe('ReactTestUtils', () => { jasmine.objectContaining({target: input}), ); }); + + [ + 'isCompositeComponentElement', + 'isCompositeComponentElementWithType', + 'getRenderedChildOfCompositeComponent', + ].forEach(fnName => { + it( + `should log a deprecation warning if ReactTestUtils.${fnName} is invoked`, + () => { + spyOn(console, 'warn'); + + try { + ReactTestUtils[fnName](); + } catch (_) {} + + expect(console.warn.calls.argsFor(0)[0]).toBe( + `Warning: ReactTestUtils.${fnName} is deprecated as of React v15.6.2.`, + ); + }, + ); + }); }); });