File tree 2 files changed +41
-26
lines changed
2 files changed +41
-26
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * Copyright (c) 2013-present, Facebook, Inc.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ */
9
+
10
+ 'use strict' ;
11
+
12
+ const mockNativeFunction = methodName => {
13
+ let warned = false ;
14
+ return function ( ) {
15
+ if ( warned ) {
16
+ return ;
17
+ }
18
+ warned = true ;
19
+ console . warn (
20
+ 'Calling .' +
21
+ methodName +
22
+ '() in the test renderer environment is not supported. Instead, mock ' +
23
+ 'out your components that use findNodeHandle with replacements that ' +
24
+ "don't rely on the native environment." ,
25
+ ) ;
26
+ } ;
27
+ } ;
28
+
29
+ const MockNativeMethods = {
30
+ measure : mockNativeFunction ( 'measure' ) ,
31
+ measureInWindow : mockNativeFunction ( 'measureInWindow' ) ,
32
+ measureLayout : mockNativeFunction ( 'measureLayout' ) ,
33
+ setNativeProps : mockNativeFunction ( 'setNativeProps' ) ,
34
+ focus : mockNativeFunction ( 'focus' ) ,
35
+ blur : mockNativeFunction ( 'blur' ) ,
36
+ } ;
37
+
38
+ module . exports = MockNativeMethods ;
Original file line number Diff line number Diff line change 6
6
*/
7
7
'use strict' ;
8
8
9
+ const MockNativeMethods = require . requireActual ( './MockNativeMethods' ) ;
9
10
const mockComponent = require . requireActual ( './mockComponent' ) ;
10
11
11
12
require . requireActual ( '../Libraries/polyfills/babelHelpers.js' ) ;
81
82
const NativeMethodsMixin =
82
83
ReactNative . __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED . NativeMethodsMixin ;
83
84
84
- const mockFunction = ( key ) => {
85
- let warned = false ;
86
- return function ( ) {
87
- if ( warned ) {
88
- return ;
89
- }
90
- warned = true ;
91
- console . warn (
92
- 'Calling .' + key + '() in the test renderer environment is not ' +
93
- 'supported. Instead, mock out your components that use ' +
94
- 'findNodeHandle with replacements that don\'t rely on the ' +
95
- 'native environment.' ,
96
- ) ;
97
- } ;
98
- } ;
85
+ Object . assign ( NativeMethodsMixin , MockNativeMethods ) ;
86
+ Object . assign ( ReactNative . NativeComponent . prototype , MockNativeMethods ) ;
99
87
100
- [
101
- 'measure' ,
102
- 'measureInWindow' ,
103
- 'measureLayout' ,
104
- 'setNativeProps' ,
105
- 'focus' ,
106
- 'blur' ,
107
- ] . forEach ( ( key ) => {
108
- NativeMethodsMixin [ key ] = mockFunction ( key ) ;
109
- ReactNative . NativeComponent . prototype [ key ] = mockFunction ( key ) ;
110
- } ) ;
111
88
return ReactNative ;
112
89
} )
113
90
. mock ( 'ensureComponentIsNative' , ( ) => ( ) => true ) ;
You can’t perform that action at this time.
0 commit comments