从'反应中找不到模块
我有以下的Jest测试:
import React from 'react';
import IndexSign from '../IndexSign';
import renderer from 'react-test-renderer';
it('renders correctly', () => {
const tree = renderer.create(
<IndexSign index={1}/>
).toJSON();
expect(tree).toMatchSnapshot();
});
我正在调用的IndexSign
组件调用此StyleSheet
组件:
import {StyleSheet} from 'react-native';
export default StyleSheet.create({
//some styles
});
为了测试,我使用Gulp:
gulp.task('tests', () => {
process.env.NODE_ENV = 'test';
return gulp.src('src').pipe(jest({
}));
});
问题是,当我运行这个测试时,我得到:
● Test suite failed to run
Cannot find module 'StyleSheet' from 'react-native-implementation.js'
at Resolver.resolveModule (../node_modules/jest-resolve/build/index.js:142:17)
at Object.StyleSheet (../node_modules/react-native/Libraries/react-native/react-native-implementation.js:98:25)
at Object.<anonymous> (styles/Styles.js:5:13)
任何想法为什么发生这种情况?
为什么它在react-native-implementation.js
搜索StyleSheet
而不是我导入的react-native
?
为什么它不能找到StyleSheet
?
我遇到了同样的问题。 添加
"jest": {
"preset": "react-native"
},
在package.json
修复了我的错误。
上一篇: Cannot find module from 'react
下一篇: SOLR slave is doing full Copy as it was not able to Delete unused Index dir