无法从'react-native-implementation.js'中找到模块 [英] Cannot find module from 'react-native-implementation.js'
本文介绍了无法从'react-native-implementation.js'中找到模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下Jest测试:
I have the following Jest test:
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
组件:
The IndexSign
component that I am calling calls this StyleSheet
component:
import {StyleSheet} from 'react-native';
export default StyleSheet.create({
//some styles
});
对于测试,我使用Gulp:
For testing, I am using Gulp:
gulp.task('tests', () => {
process.env.NODE_ENV = 'test';
return gulp.src('src').pipe(jest({
}));
});
问题是,当我运行这个测试时,我得到:
The problem is that when I run this test, I get:
● 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)
为什么会出现这种情况?
Any idea why this is happening?
为什么它会在 react-native-implementation.js中搜索
而不是 StyleSheet
react-native
,我导入了它?
Why is it searching for StyleSheet
in react-native-implementation.js
rather than react-native
, which I imported?
为什么找不到 StyleSheet
?
推荐答案
我遇到了同样的问题。添加
I ran into the same issue. Adding
"jest": {
"preset": "react-native"
},
在 package.json
我。
这篇关于无法从'react-native-implementation.js'中找到模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文