home.test.js
import React from 'react';
import Home from './index';
import renderer from 'react-test-renderer';
it('renders home', ()=> {
const view = renderer.create(
<Home></Home>
).toJSON();
expect(view).toMatchSnapshot();
});
不幸的是,我不知道这里有什么问题。我认为测试写得很好。
任何帮助都会很棒。
答案 0 :(得分:0)
我如何解决错误让我的测试无法运行
进入此错误,这使我的测试无法运行
经过几个小时的挫折,我删除了 node_modules 文件夹两次并重新安装并通过Stackoverflow和Google搜索而没有任何解决方案,我决定创建一个新的CRNA项目,看看它是否会有同样的问题。 当我看到新回购中没有问题时,我使用以下步骤使其工作:
``` {
"devDependencies": {
"react-native-scripts": "1.5.0",
"jest-expo": "^21.0.2",
"react-test-renderer": "16.0.0-alpha.12"
},
"jest": {
"preset": "jest-expo",
"transformIgnorePatterns": [
"node_modules/(?!react-native|expo|react-navigation|native-base-shoutem-theme|@shoutem/theme|@shoutem/animation|@shoutem/ui|tcomb-form-native)"
]
},
"dependencies": {
"react-native": “0.48.4”,
"expo": "^21.0.2",
"react": "16.0.0-alpha.12"
},
3. The core difference was in upgrading react-native from 0.48.0 to 0.48.4; react-native-scripts from 1.2.1 to 1.5.0 and including the transformIgnorePatterns under the jest option.
NOTE: The portion from *native-base* in the transformIgnorePatterns was included because I used NativeBase in the project.
4. I then added a .babelrc with the following details:
{
"presets": ["babel-preset-expo"],
"env": {
"development": {
"plugins": ["transform-react-jsx-source"]
}
}
}
``` 5.运行测试现在给我结果:
Passing Tests 所有测试都是绿色的