为什么反对.anonymous
package.json:
package.json:
{
"name": "SmartConverter",
"version": "1.0.0",
"main": "./src/js/main.js",
"scripts": {
"test": "jest --coverage",
"build": "webpack --config ./scripts/*/webpack.config.js"
},
"repository": "https://github.com/raushankumarnitdgp/SmartConverter.git",
"author": "raushankumarnitdgp <raushankumar.nitdgp@gmail.com>",
"license": "MIT",
"dependencies": {
"babel-cli": "^6.24.1",
"babel-core": "^6.25.0",
"babel-jest": "^20.0.3",
"babel-loader": "^7.1.1",
"babel-preset-es2015": "^6.24.1",
"eslint": "^4.4.1",
"jest": "^20.0.4",
"jest-cli": "^20.0.4",
"regenerator-runtime": "^0.10.5",
"webpack": "^3.5.2"
}
}
最佳答案
您在错误 stracktrace 中看到的 anonymous
关键字只是告诉您错误发生在匿名函数中。匿名函数是没有名字的函数,通常用作回调,但并非总是如此。例如:
function main() {
myLibrary.doSomething('foo', function() {
console.log('I have finished')
})
}
传递给 myLibrary.doSomething
的函数是一个匿名函数。您看到的错误似乎发生在 phone.js
文件的第 20 行。检查您在哪里使用 .length
。
关于javascript - Jest : TypeError: Cannot read property 'length' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45663988/