[英]"describe is not defined" mocha (windows user)
我正在嘗試測試這個
var assert = require("assert");
describe("test suite math opreations",function(){
it("add of two",function(){
var a = 10;
var b = 10;
var c = a+b;
assert.equal(c,20);
});
it("sub of two",function(){
var a = 10;
var b = 10;
var c = a-b;
assert.equal(c,0);
});
it("multi of two",function(){
var a = 10;
var b = 10;
var c = a*b;
assert.equal(c,100);
});
it("division of two",function(){
var a = 10;
var b = 10;
var c = a/b;
assert.equal(c,1);
});
});
文件名為 test 並將方向更改為終端中的文件並寫入
node test.js
終端說“描述未定義”
我嘗試了很多東西
重新安裝節點和摩卡
將文件移動到很多文件夾
最后.....我沒有解決問題:)
你必須安裝 mocha,然后用它的二進制運行這個測試文件。
您可以使用npm i -D mocha
將它安裝到您的項目依賴項中,然后添加一個新的 npm 腳本,例如“test”,並使其從您的 node_modules 運行“mocha”:
{
"name": "my-project",
"version": "1.0.0",
"description": "",
"scripts": {
"test": "mocha"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"mocha": "^10.2.0"
}
}
然后只需使用npm test
,或npm run test
。
或者,您可以使用npm i -g mocha
在您的計算機上全局安裝它,然后運行
mocha
而不是你的node test.js
命令。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.