jestjs - 类型错误 : Cannot read property 'LENGTH_LONG' of undefined

标签 jestjs react-native react-native-navigation

我正在 React Native 中进行 Jest 测试,并且在我的项目中使用了 Snackbar。在执行 jest 时,我收到此错误。“LENGTH_LONG”是 snackbar 中的内置变量。我发布了我使用“LENGTH_LONG”变量和错误消息的位置。请大家帮帮我

 jest "login"

 FAIL  __tests__\jest\LoginScreen.test.js
  ● Test suite failed to run

    TypeError: Cannot read property 'LENGTH_LONG' of undefined

      10 |     ScrollView
      11 | } from "react-native";
    > 12 | import Snackbar from 'react-native-snackbar';
      13 |
      14 | import { connect } from "react-redux";
      15 | import { Button, Text, Divider } from "react-native-elements";

      at Object.<anonymous> (node_modules/react-native-snackbar/lib/index.js:1:252)
      at Object.<anonymous> (src/screens/login/loginScreen.js:12:26)
      at Object.<anonymous> (__tests__/jest/LoginScreen.test.js:3:18)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        2.689s, estimated 4s
Ran all test suites matching /login/i.

代码是

render() {
        return (
            <View style={styles.mainContainer}>
                {this.renderTopLogoContainer()}
                {this.renderBottomContainer()}

                {this.props.hasError ? Snackbar.show({
                    title: this.props.error.display_message,
                    duration: Snackbar.LENGTH_LONG
                }) : null}
            </View>
        );
    }

最佳答案

https://github.com/cooperka/react-native-snackbar/tree/master/examplemocks文件夹中添加react-native-snackbar.js文件

关于jestjs - 类型错误 : Cannot read property 'LENGTH_LONG' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51174042/

相关文章:

angular - 单元测试 ngAfterViewInit

javascript - 在 Typescript 中测试类私有(private)属性访问器时遇到问题

javascript - 如何在单元测试中触发 FileReader 的 `onloadend`?

node.js - 无法在此项目中找到 expo - 你运行 yarn/npm install 了吗? npm已安装,expo目录存在

ios - react native 导航与 react native Sentry ios

ios - 是否可以在标签栏项目上绘制在线图像?

reactjs - React Redux 连接组件与异步 Action 测试

javascript - 将图像设置为相对于屏幕尺寸的尺寸?

javascript - 世博会去 Stripe : Native module cannot be null

react-native - 使用react-native-navigation时如何在显示组件时触发事件?