[英]How to configure Mocha with WebStorm
我在运行Mocha测试时遇到问题。
我为WebStorm进行了配置,当我使用WebStorm测试运行Mocha时,我的测试正常运行。
但是,当我从我的终端使用'node'filename'运行测试时,出现“ describe is not defined”错误。
const assert = require('assert');
describe('login', function() {
describe('find_user', function() {
it('should find the user after login', function() {
assert.equal([1,2,3].indexOf(4), -1);
// should be code for login
});
});
});
describe('register', function() {
describe('register_user', function() {
it('should find the user after register', function() {
assert.equal([1,2,3].indexOf(4), -1);
// should be code for register
});
});
});
describe('contact', function() {
describe('contact_us', function() {
it('should find the contact message within the database', function()
{
assert.equal([1,2,3].indexOf(4), -1);
// should be code for contact us
});
});
});
将防雷代码修改为此版本后:我收到错误消息“描述不是函数”。
const assert = require('assert');
const mocha = require('mocha');
const describe = mocha.describe;
const it = mocha.it;
describe('login', function() {
describe('find_user', function() {
it('should find the user after login', function() {
assert.equal([1,2,3].indexOf(4), -1);
// should be code for login
});
});
});
describe('register', function() {
describe('register_user', function() {
it('should find the user after register', function() {
assert.equal([1,2,3].indexOf(4), -1);
// should be code for register
});
});
});
describe('contact', function() {
describe('contact_us', function() {
it('should find the contact message within the database', function()
{
assert.equal([1,2,3].indexOf(4), -1);
// should be code for contact us
});
});
});
{
"name": "couponsystem",
"version": "1.0.0",
"description": "electron desktop project",
"main": "js/src/app.js",
"scripts": {
"start": "electron ."
},
"dependencies": {
"bootstrap": "^4.2.1",
"electron": "^4.0.0",
"handlebars": "^4.0.12",
"sequelize": "^4.42.0"
},
"devDependencies": {
"mocha": "^5.2.0"
},
"author": "maks burkov",
"license": "ISC"
}
您能解释一下从终端运行测试所需的配置吗?
您需要使用mocha测试运行程序来运行测试,只是将测试文件传递给节点解释器就不能了。
只需在package.json
的"scripts": {}
部分中添加"test": "mocha"
,然后在终端中运行npm test
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.