我正在用react native做开玩笑的测试,并且我在项目中使用了Snackbar。在执行笑话时,我收到此错误。“ LENGTH_LONG”是小吃店中的内置变量。我正在发布使用“ 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>
);
}
答案 0 :(得分:0)
https://github.com/cooperka/react-native-snackbar/tree/master/example 在模拟文件夹
中添加react-native-snackbar.js文件答案 1 :(得分:0)
您没有提到要在ios还是android中运行,最近我在ios中看到了此问题,因为我错过了安装Pod的操作。
尝试一下:
在ios目录中安装Pod
react-native run-ios
如果愿意,还可以使用npm代替yarn。
答案 2 :(得分:0)