我是新来开玩笑的
在我的项目的- package.json中设置jest配置后,
Package.json
"jest": {
"preset": "react-native",
"verbose": true,
"moduleDirectories": ["node_modules", "src"],
"transformIgnorePatterns": ["node_modules/(?!(react-native-cookies)/)"]
},
我已经尝试过忽略所有节点模块:
"transformIgnorePatterns": ["node_modules"]
但对我不起作用
和.babelrc
{
"presets": ["react-native"]
}
我的登录屏幕-测试.js代码:-
TestCase
import 'react-native';
import React from 'react';
import LoginScreen from '../src/components/LoginScreen';
import renderer from 'react-test-renderer';
it('renders correctly', () => {
const hello = renderer.create(<LoginScreen/>).toJSON();
expect(hello).toMatchSnapshot();
});
我开始运行--> npm test或npm test -u
它反映了我的以下错误:
终端输出
FAIL tests/LoginScreen-test.js测试套件运行失败
/Users/Documents/Projects/node_modules/react-native/Libraries/Utilities/Platform.ios.js:31 get isTesting():boolean {^ SyntaxError:意外标记:在ScriptTransformer._transformAndBuildScript isTesting at Object.get Platform as Platform at Object。(node_modules/react-native-cookies/index.js:9:17)
我想忽略TransformIgnorePattern的所有节点模块,但它似乎对我的React-Native预置无效。
寻找有用的答案...
发布于 2018-09-13 07:01:54
此错误表明"react-native“尚未转换:react-native/Libraries/Utilities/Platform.ios.js:31
"transformIgnorePatterns": ["node_modules"]
不会工作,因为它几乎是默认行为。
您是否尝试过使用official recommendation配置?对于您的项目,它应该如下所示:
"transformIgnorePatterns": [ "node_modules/(?!(react-native|react-native-cookies)/)" ]
?!
很重要,因为它意味着忽略node_modules中除react-native
和react-native-cookies
之外的所有内容。
https://stackoverflow.com/questions/50388367
复制相似问题