我正在 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/example 在mocks文件夹中添加react-native-snackbar.js文件
关于jestjs - 类型错误 : Cannot read property 'LENGTH_LONG' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51174042/