From 890409835ee0d15d7aa9816c1f06888aa487b3b7 Mon Sep 17 00:00:00 2001 From: Julien Moutte Date: Thu, 21 Sep 2017 08:30:59 +0200 Subject: [PATCH 1/3] Direct assignment of the ref to avoid warning when mocking. 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. --- Libraries/Components/DatePicker/DatePickerIOS.ios.js | 2 +- Libraries/Components/Picker/PickerIOS.ios.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Libraries/Components/DatePicker/DatePickerIOS.ios.js b/Libraries/Components/DatePicker/DatePickerIOS.ios.js index 5ef82af2094bdd..ba392dd99dedca 100644 --- a/Libraries/Components/DatePicker/DatePickerIOS.ios.js +++ b/Libraries/Components/DatePicker/DatePickerIOS.ios.js @@ -125,7 +125,7 @@ const DatePickerIOS = createReactClass({ return ( { this._picker = picker; } } + ref={this._picker} style={styles.datePickerIOS} date={props.date.getTime()} maximumDate={ diff --git a/Libraries/Components/Picker/PickerIOS.ios.js b/Libraries/Components/Picker/PickerIOS.ios.js index 81911b4bc16143..5fb9a34e53a897 100644 --- a/Libraries/Components/Picker/PickerIOS.ios.js +++ b/Libraries/Components/Picker/PickerIOS.ios.js @@ -66,7 +66,7 @@ var PickerIOS = createReactClass({ return ( this._picker = picker} + ref={this._picker} style={[styles.pickerIOS, this.props.itemStyle]} items={this.state.items} selectedIndex={this.state.selectedIndex} From 33144f99b16ebf22f5b56d1e75ea9bd8c2b91c78 Mon Sep 17 00:00:00 2001 From: Julien Moutte Date: Sat, 7 Oct 2017 08:51:23 +0200 Subject: [PATCH 2/3] Mock Native components with a class component to avoid stateless refs warnings. --- jest/setup.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/jest/setup.js b/jest/setup.js index 26b710e93f4306..d6e3c4e5cdc9c7 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, + ); + } + }; }); From 2a0270e0a9c930a326f8bdf1fec4e1da8e6df1f6 Mon Sep 17 00:00:00 2001 From: Julien Moutte Date: Sun, 8 Oct 2017 17:51:12 +0200 Subject: [PATCH 3/3] Revert "Direct assignment of the ref to avoid warning when mocking." This reverts commit 890409835ee0d15d7aa9816c1f06888aa487b3b7. --- Libraries/Components/DatePicker/DatePickerIOS.ios.js | 2 +- Libraries/Components/Picker/PickerIOS.ios.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Libraries/Components/DatePicker/DatePickerIOS.ios.js b/Libraries/Components/DatePicker/DatePickerIOS.ios.js index ba392dd99dedca..5ef82af2094bdd 100644 --- a/Libraries/Components/DatePicker/DatePickerIOS.ios.js +++ b/Libraries/Components/DatePicker/DatePickerIOS.ios.js @@ -125,7 +125,7 @@ const DatePickerIOS = createReactClass({ return ( { this._picker = picker; } } style={styles.datePickerIOS} date={props.date.getTime()} maximumDate={ diff --git a/Libraries/Components/Picker/PickerIOS.ios.js b/Libraries/Components/Picker/PickerIOS.ios.js index 5fb9a34e53a897..81911b4bc16143 100644 --- a/Libraries/Components/Picker/PickerIOS.ios.js +++ b/Libraries/Components/Picker/PickerIOS.ios.js @@ -66,7 +66,7 @@ var PickerIOS = createReactClass({ return ( this._picker = picker} style={[styles.pickerIOS, this.props.itemStyle]} items={this.state.items} selectedIndex={this.state.selectedIndex}