Skip to content

Commit bbceb48

Browse files
jmouttefacebook-github-bot
authored andcommitted
Direct assignment of the ref to avoid warning when mocking.
Summary: When Jest is mocking native components that are assigned a ref with an arrow function, a warning is generated about stateless components which can not have a ref. This does not happen when the ref is assigned directly. Fixes #16045. <!-- Thank you for sending the PR! We appreciate you spending the time to work on these changes. Help us understand your motivation by explaining why you decided to make this change. You can learn more about contributing to React Native here: http://facebook.github.io/react-native/docs/contributing.html Happy contributing! --> The test provided in the related issue is used to validate the fix. I don't know how to detect console warnings in a Jest test. Closes #16046 Differential Revision: D6017903 Pulled By: ericnakagawa fbshipit-source-id: a7ed61c39f141a4094f08fc875289a7a79ebe9e8
1 parent 3eced7f commit bbceb48

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

jest/setup.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,13 @@ jest
313313
jest.doMock('requireNativeComponent', () => {
314314
const React = require('react');
315315

316-
return viewName => props => React.createElement(
317-
viewName,
318-
props,
319-
props.children,
320-
);
316+
return viewName => class extends React.Component {
317+
render() {
318+
return React.createElement(
319+
viewName,
320+
this.props,
321+
this.props.children,
322+
);
323+
}
324+
};
321325
});

0 commit comments

Comments
 (0)