|
11 | 11 | 'use strict';
|
12 | 12 |
|
13 | 13 | let React;
|
| 14 | +let ReactFeatureFlags; |
14 | 15 | let StrictMode;
|
15 | 16 | let ReactNative;
|
16 | 17 | let createReactClass;
|
17 | 18 | let createReactNativeComponentClass;
|
18 | 19 | let UIManager;
|
19 | 20 | let NativeMethodsMixin;
|
20 | 21 |
|
| 22 | +const SET_NATIVE_PROPS_DEPRECATION_MESSAGE = |
| 23 | + 'Warning: Calling ref.setNativeProps(nativeProps) ' + |
| 24 | + 'is deprecated and will be removed in a future release. ' + |
| 25 | + 'Use the setNativeProps export from the react-native package instead.' + |
| 26 | + "\n\timport {setNativeProps} from 'react-native';\n\tsetNativeProps(ref, nativeProps);\n"; |
| 27 | + |
21 | 28 | describe('ReactNative', () => {
|
22 | 29 | beforeEach(() => {
|
23 | 30 | jest.resetModules();
|
24 | 31 |
|
25 | 32 | React = require('react');
|
26 | 33 | StrictMode = React.StrictMode;
|
| 34 | + ReactFeatureFlags = require('shared/ReactFeatureFlags'); |
| 35 | + ReactFeatureFlags.warnAboutDeprecatedSetNativeProps = true; |
27 | 36 | ReactNative = require('react-native-renderer');
|
28 | 37 | UIManager = require('UIManager');
|
29 | 38 | createReactClass = require('create-react-class/factory')(
|
@@ -98,7 +107,7 @@ describe('ReactNative', () => {
|
98 | 107 | expect(UIManager.updateView).toHaveBeenCalledTimes(4);
|
99 | 108 | });
|
100 | 109 |
|
101 |
| - it('should not call UIManager.updateView from setNativeProps for properties that have not changed', () => { |
| 110 | + it('should not call UIManager.updateView from ref.setNativeProps for properties that have not changed', () => { |
102 | 111 | const View = createReactNativeComponentClass('RCTView', () => ({
|
103 | 112 | validAttributes: {foo: true},
|
104 | 113 | uiViewClassName: 'RCTView',
|
@@ -132,10 +141,19 @@ describe('ReactNative', () => {
|
132 | 141 | );
|
133 | 142 | expect(UIManager.updateView).not.toBeCalled();
|
134 | 143 |
|
135 |
| - viewRef.setNativeProps({}); |
| 144 | + expect(() => { |
| 145 | + viewRef.setNativeProps({}); |
| 146 | + }).toWarnDev([SET_NATIVE_PROPS_DEPRECATION_MESSAGE], { |
| 147 | + withoutStack: true, |
| 148 | + }); |
136 | 149 | expect(UIManager.updateView).not.toBeCalled();
|
137 | 150 |
|
138 |
| - viewRef.setNativeProps({foo: 'baz'}); |
| 151 | + expect(() => { |
| 152 | + viewRef.setNativeProps({foo: 'baz'}); |
| 153 | + }).toWarnDev([SET_NATIVE_PROPS_DEPRECATION_MESSAGE], { |
| 154 | + withoutStack: true, |
| 155 | + }); |
| 156 | + |
139 | 157 | expect(UIManager.updateView).toHaveBeenCalledTimes(1);
|
140 | 158 | expect(UIManager.updateView).toHaveBeenCalledWith(
|
141 | 159 | expect.any(Number),
|
@@ -164,7 +182,9 @@ describe('ReactNative', () => {
|
164 | 182 | 11,
|
165 | 183 | );
|
166 | 184 |
|
| 185 | + ReactNative.setNativeProps(viewRef, {}); |
167 | 186 | expect(UIManager.updateView).not.toBeCalled();
|
| 187 | + |
168 | 188 | ReactNative.setNativeProps(viewRef, {foo: 'baz'});
|
169 | 189 | expect(UIManager.updateView).toHaveBeenCalledTimes(1);
|
170 | 190 | expect(UIManager.updateView).toHaveBeenCalledWith(
|
|
0 commit comments