Skip to content

Commit

Permalink
Add deprecation warning for test utils to be removed
Browse files Browse the repository at this point in the history
  • Loading branch information
BenBrostoff committed Jul 6, 2017
1 parent 594bc35 commit 8088c3f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
4 changes: 3 additions & 1 deletion scripts/fiber/tests-failing.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@

src/renderers/dom/test/__tests__/ReactTestUtils-test.js
* should log a deprecation warning if ReactTestUtils.isCompositeComponentElementWithType is invoked
* should log a deprecation warning if ReactTestUtils.getRenderedChildOfCompositeComponent is invoked
1 change: 1 addition & 0 deletions scripts/fiber/tests-passing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1972,6 +1972,7 @@ 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

src/renderers/native/__tests__/ReactNativeAttributePayload-test.js
* should work with simple example
Expand Down
19 changes: 16 additions & 3 deletions src/renderers/dom/test/ReactTestUtilsEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -217,7 +216,6 @@ var ReactTestUtils = {
constructor === type);
},

// TODO: deprecate? It's undocumented and unused.
getRenderedChildOfCompositeComponent: function(inst) {
if (!ReactTestUtils.isCompositeComponent(inst)) {
return null;
Expand Down Expand Up @@ -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;
22 changes: 22 additions & 0 deletions src/renderers/dom/test/__tests__/ReactTestUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -843,5 +843,27 @@ 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');

class MyComponent extends React.Component {
render() {
return <div />;
}
}
const instance = ReactTestUtils.renderIntoDocument(<MyComponent />);
ReactTestUtils[fnName](instance);

expect(console.warn.calls.argsFor(0)[0]).toBe(
`Warning: ReactTestUtils.${fnName} is deprecated as of React v15.6.2.`,
);
});
});
});
});

0 comments on commit 8088c3f

Please sign in to comment.