我正在尝试从Jest React tutorial运行React示例,但收到错误
λ npm test
> ...
> jest
Found 1 matching tests...
FAIL __tests__\CheckboxWithLabel-test.js (0.551s)
npm ERR! Test failed. See above for more details.
npm ERR! not ok code 0
我已经从示例中直接复制了代码。 package.json如下:
{
"dependencies": {
"react": "*",
"react-tools": "*"
},
"scripts":{
"test": "jest"
},
"jest": {
"scriptPreprocessor": "<rootDir>/preprocessor.js",
"unmockedModulePathPatterns": [
"<rootDir>/node_modules/react"
]
},
"devDependencies": {
"jest-cli": "~0.1.17"
}
}
关于如何解决这些错误并成功运行示例测试的任何想法?我很可能会漏掉一个(或多个)重要细节,但不能完全确定是什么。哦,这是有什么用,如果有影响,我可以在Windows上运行。我真的很想对我的react组件进行一些测试(那里也有一些麻烦,所以从基本示例开始)-任何帮助将不胜感激:)
最佳答案
我在他们的github页面上创建了一个issue。等待找出它是否实际上是与Windows相关的问题
同时,通过仅指定模块名称而不是相对路径最终使它起作用
"unmockedModulePathPatterns": ["react"]
关于unit-testing - 开玩笑的React示例,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24981486/