开玩笑:类型错误:无法读取未定义的属性“长度”

Rau*_*mar 6 javascript unit-testing jestjs

在此输入图像描述

为什么它 object.anonymous

包.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"
    }
}
Run Code Online (Sandbox Code Playgroud)

Ign*_*cio 2

您在错误 stracktrace 中看到的关键字anonymous只是告诉您错误发生在匿名函数中。匿名函数是没有名称的函数,通常用作回调,但并非总是如此。例如:

function main() {
  myLibrary.doSomething('foo', function() {
    console.log('I have finished')
  })
}
Run Code Online (Sandbox Code Playgroud)

传递给的函数myLibrary.doSomething是匿名函数。您看到的错误似乎发生在phone.js文件第 20 行中。检查您在哪里使用.length.