From bbceb48dbb2e1a40f9f50bed5a2ea7f3bc3c93c0 Mon Sep 17 00:00:00 2001 From: Julien Moutte Date: Mon, 9 Oct 2017 21:30:41 -0700 Subject: [PATCH] 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. 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 https://github.com/facebook/react-native/pull/16046 Differential Revision: D6017903 Pulled By: ericnakagawa fbshipit-source-id: a7ed61c39f141a4094f08fc875289a7a79ebe9e8 --- jest/setup.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/jest/setup.js b/jest/setup.js index 26b710e93..d6e3c4e5c 100644 --- a/jest/setup.js +++ b/jest/setup.js @@ -313,9 +313,13 @@ jest jest.doMock('requireNativeComponent', () => { const React = require('react'); - return viewName => props => React.createElement( - viewName, - props, - props.children, - ); + return viewName => class extends React.Component { + render() { + return React.createElement( + viewName, + this.props, + this.props.children, + ); + } + }; });