-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RN: Refactor
MockNativeMethods
in Jest
Reviewed By: sahrens Differential Revision: D7917498 fbshipit-source-id: 97636080588bf2641a56256688cb0f2ec81ae463
- Loading branch information
1 parent
67dbcbd
commit 5d4c542
Showing
2 changed files
with
41 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* Copyright (c) 2013-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const mockNativeFunction = methodName => { | ||
let warned = false; | ||
return function() { | ||
if (warned) { | ||
return; | ||
} | ||
warned = true; | ||
console.warn( | ||
'Calling .' + | ||
methodName + | ||
'() in the test renderer environment is not supported. Instead, mock ' + | ||
'out your components that use findNodeHandle with replacements that ' + | ||
"don't rely on the native environment.", | ||
); | ||
}; | ||
}; | ||
|
||
const MockNativeMethods = { | ||
measure: mockNativeFunction('measure'), | ||
measureInWindow: mockNativeFunction('measureInWindow'), | ||
measureLayout: mockNativeFunction('measureLayout'), | ||
setNativeProps: mockNativeFunction('setNativeProps'), | ||
focus: mockNativeFunction('focus'), | ||
blur: mockNativeFunction('blur'), | ||
}; | ||
|
||
module.exports = MockNativeMethods; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters