我正在尝试将我的应用与玩笑集成。当我运行yarn test
时,出现以下错误,甚至忽略转换似乎都无效:
╰─± yarn test
yarn run v1.17.3
$ jest
FAIL __tests__/App-test.js
● Test suite failed to run
TypeError: Cannot read property 'propTypes' of undefined
at propTypes (node_modules/react-native/Libraries/Animated/src/createAnimatedComponent.js:178:31)
at Object.oldCreate [as createAnimatedComponent] (node_modules/react-native/jest/setup.js:143:23)
at Object.createAnimatedComponent (node_modules/react-navigation-stack/lib/commonjs/views/BorderlessButton.js:1:1222)
at Object.require (node_modules/react-navigation-stack/lib/commonjs/views/TouchableItem.js:1:1053)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 8.653s
Ran all test suites.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
这是package.json中我最喜欢的配置:
"jest": {
"preset": "react-native",
"transformIgnorePatterns": [
"node_modules/(?!((jest-)?react-native|react-clone-referenced-element|expo(nent)?|@expo(nent)?/.*|react-navigation|@react-navigation/.*|sentry-expo|native-base))"
]
}
这是我的基本测试文件:
/**
* @format
*/
import "react-native";
import React from "react";
import App from "../src/App";
// Note: test renderer must be required after react-native.
import renderer from "react-test-renderer";
it("renders correctly", () => {
renderer.create(<App />);
});
和App.js内容:
import React, {Component} from "react";
import {Provider as ThemeProvider} from "react-native-paper";
import {Provider as ReduxProvider} from "react-redux";
import {PersistGate} from "redux-persist/integration/react";
import Pushe from "react-native-pushe";
import {ReduxNetworkProvider} from "react-native-offline";
import {configureI18n} from "i18n";
import {store, persistor} from "store";
import Navigator from "navigator";
import NavigationService from "navigator/NavigationService";
import theme from "theme";
import Feedback from "containers/Feedback";
export default class App extends Component {
constructor(props) {
super(props);
configureI18n();
Pushe.initialize(true);
}
componentDidMount() {
if (global.HermesInternal != null) {
console.log("Herms enabled!");
}
}
setNavigatorRef = (ref) => NavigationService.setTopLevelNavigator(ref);
render() {
return (
<ReduxProvider store={store}>
<ReduxNetworkProvider pingInterval={30000} pingOnlyIfOffline={true}>
<PersistGate loading={null} persistor={persistor}>
<ThemeProvider theme={theme}>
<>
<Navigator ref={this.setNavigatorRef} uriPrefix="test://" />
<Feedback />
</>
</ThemeProvider>
</PersistGate>
</ReduxNetworkProvider>
</ReduxProvider>
);
}
}