How to mock an adaptive module (not a third-party module) as a joke

I am trying to mock a module that comes with reactive (non-third-party modules) , such as LayoutAnimation:

import * as RN from 'react-native'

RN.LayoutAnimation = jest.fn()

But test fail:

TypeError: Cannot read property 'decelerationRate' of undefined

  at Object.<anonymous> (node_modules/react-native/Libraries/Components/WebView/WebView.ios.js:555:3254)
  at Object.get WebView [as WebView] (node_modules/react-native/Libraries/react-native/react-native-implementation.js:73:22)

Is there any other way to mock the RN module, for example, LayoutAnimationor any other adaptive (non-third-party) module?

+4
source share
2 answers

Try to just do jest.mock('LayoutAnimation');

+4
source

You received this message because of line # 217 in / node_modules / react-native / Libraries / Components / WebView / WebView.ios.js

decelerationRate: ScrollView.propTypes.decelerationRate

Since ScrollView mocks ScrollView.propTypes === undefined

I solved this problem by adding:

import {PropTypes} from 'react';
ScrollView.propTypes = { decelerationRate: PropTypes.number };

script (, setupTestFrameworkScriptFile jest package.json);

0

Source: https://habr.com/ru/post/1680820/


All Articles