Mock ReactNative.NativeComponent native methods in jest
Reviewed By: yungsters Differential Revision: D7218964 fbshipit-source-id: f4b25a533b7e150c978863ff8411dc80937a4fed
This commit is contained in:
parent
b6b80f6a70
commit
3e9a371ace
|
@ -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;
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue