我正在设置nodejs以便使用jest javascript测试框架测试我的javascript代码。我做错了什么?
package.json
文件{
"name": "institute-jest",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "jest"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.26.3",
"babel-jest": "^23.4.0",
"jest": "^23.4.1",
"regenerator-runtime": "^0.12.0"
}
}
在终端中运行npm test
后,我收到以下错误消息
(node:5088) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'close' of undefined
at Object.<anonymous> (C:\Users\Olakunle-PC\Desktop\nodejs\HomeStudyLabs\node_modules\jest\node_modules\chalk\index.js:72:75)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at _load_chalk (C:\Users\Olakunle-PC\Desktop\nodejs\HomeStudyLabs\node_modules\jest\node_modules\jest-cli\build\cli\index.js:67:43)
at Object.<anonymous> (C:\Users\Olakunle-PC\Desktop\nodejs\HomeStudyLabs\node_modules\jest\node_modules\jest-cli\build\cli\index.js:29:32)
(node:5088) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:5088) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate
the Node.js process with a non-zero exit code.
答案 0 :(得分:0)
如果遇到未定义的错误,则需要确保为哪个变量抛出未定义的错误分配了一个值。
更多详细信息检查链接detail 以下代码可能有助于调试:
function test(t) {
if (t === undefined) {
console.log(t.tt)
}
return t;
}
答案 1 :(得分:0)
我在下面做了以下操作以解决该问题
node_modules
目录。package-lock.json
文件。npm clear cache --force
。npm install
。