Permalink
Browse files

Mock ReactNative.NativeComponent native methods in jest

Reviewed By: yungsters

Differential Revision: D7218964

fbshipit-source-id: f4b25a533b7e150c978863ff8411dc80937a4fed
  • Loading branch information...
TheSavior authored and facebook-github-bot committed Mar 9, 2018
1 parent b6b80f6 commit 3e9a371ace5f25b2eb7a0d30177251f8a0c10ed9
Showing with 15 additions and 9 deletions.
  1. +15 −9 jest/setup.js
View
@@ -80,16 +80,10 @@ jest
const ReactNative = require.requireActual('ReactNative');
const NativeMethodsMixin =
ReactNative.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.NativeMethodsMixin;
[
'measure',
'measureInWindow',
'measureLayout',
'setNativeProps',
'focus',
'blur',
].forEach((key) => {
const mockFunction = (key) => {
let warned = false;
NativeMethodsMixin[key] = function() {
return function() {
if (warned) {
return;
}
@@ -101,6 +95,18 @@ jest
'native environment.',
);
};
};
[
'measure',
'measureInWindow',
'measureLayout',
'setNativeProps',
'focus',
'blur',
].forEach((key) => {
NativeMethodsMixin[key] = mockFunction(key);
ReactNative.NativeComponent.prototype[key] = mockFunction(key);
});
return ReactNative;
})

0 comments on commit 3e9a371

Please sign in to comment.