出于某种原因,我的 mocha 测试脚本抛出了“describe is not defined”的异常。
我已经阅读并尝试了这些 SO 问题建议的解决方案,但没有成功:
describe is not a function
"Mocha describe is not defined duplicate"
其他链接是:
typescript mocha describe is not a function
这是我的 VSCode launch.json。
{
"type": "node",
"request": "launch",
"name": "Mocha Tests",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"-u",
"tdd",
"--timeout",
"999999",
"--colors",
"${workspaceRoot}/dist/tests/**/*.js"
],
"outFiles": ["${workspaceFolder}/dist/tests/**/*.js"],
"sourceMaps": true,
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
}
这是我的 mocha 测试脚本:
import "mocha";
import assert = require("assert");
describe("Init", () => {
before(() => {
console.log("before-hook");
});
it("connected", () => {
assert(true, "is not true");
});
});
这是我的 tsconfig.json:
{
"compilerOptions": {
"experimentalDecorators": true,
"strict": true,
"noImplicitAny": false,
"module": "commonjs",
"target": "es6",
"lib": [ "es6" ],
"sourceMap": true,
"outDir": "dist",
"moduleResolution": "node",
"resolveJsonModule": true,
"strictNullChecks": true,
"allowJs": false,
"checkJs": false,
"types": [
"node"
]
},
"compileOnSave": true
}
我在这里做错了什么?我真的需要重新开始使用 mocha。
最佳答案
在这里回答我自己的问题。
我在安装 Mocha 6.1.1 后解决了这个问题。
在 launch.json 上,将 args 数组从“tdd”更改为“bdd”,以便:
"-u", "bdd"
版本 5.x 使用“tdd”选项,因此下一个主要版本导致了配置编写错误的问题。
关于typescript - Describe is not defined exception on Typescript, Mocha 和 VSCode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55258209/