我是jest的新手,
在我的项目的package.json中设置了jest配置后,
Package.json
"jest": {
"preset": "react-native",
"verbose": true,
"moduleDirectories": ["node_modules", "src"],
"transformIgnorePatterns": ["node_modules/(?!(react-native-cookies)/)"]
},
我已经尝试过以下方法来忽略所有的 node 模块:
"transformIgnorePatterns": ["node_modules"]
但对我来说没有起作用
以及.babelrc
{
"presets": ["react-native"]
}
我的 LoginScreen-Test.js 代码:
测试用例
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: Unexpected token :
at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:316:17)
at Object.get Platform [as Platform] (node_modules/react-native/Libraries/react-native/react-native-implementation.js:111:27)
at Object.<anonymous> (node_modules/react-native-cookies/index.js:9:17)
我想通过TransformIgnorePattern来忽略所有Node模块,但似乎对我的React-Native预设不起作用。寻找有用的答案...结果为:
我想通过TransformIgnorePattern来忽略所有Node模块,但似乎对我的React-Native预设不起作用。寻找有用的答案...
--no-cache
运行它吗? - Andreas Köberle"test": "jest --no-cache"
,但是没有任何新的进展。 - Lucifer_Latif0.56.0
和Jest23.6.0
。似乎除了一些“清除依赖并重新安装”之外,没有任何答案……即使当然清除锁定也不起作用。 - Chris