本文介绍了开玩笑:为什么它会因TypeError失败:路径必须是字符串.收到未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我编写了一个React应用程序,并开玩笑地编写了单元测试.
I wrote a React application and used jest to write unit tests.
当我通过"jest --config = jest.config.json --watch"运行它时,出现以下错误:
when I run it by "jest --config=jest.config.json --watch" I get the following error:
TypeError: Path must be a string. Received undefined
at assertPath (path.js:7:11)
at Object.relative (path.js:1226:5)
我的jest.config.json是:
My jest.config.json is:
{
"snapshotSerializers": [
"enzyme-to-json/serializer"
],
"transformIgnorePatterns": [
"node_modules/(?!(react-native|my-project|redux-persist)/)"
]
}
推荐答案
由于我使用create-react-app构建了我的应用程序,因此我只运行了"npm test",并且测试成功运行.
Since I built my app using create-react-app, I just ran "npm test" and the tests ran successfully.
我了解到Jest已自动包含在项目中,并且可能在package.json中手动添加笑话是无效的.
I understood that Jest is automatically included in the project, andprobably adding manually jest to package.json is not effective.
这篇关于开玩笑:为什么它会因TypeError失败:路径必须是字符串.收到未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!