【发布时间】:2018-12-26 10:50:38
【问题描述】:
我在运行 Mocha 测试时遇到问题。
我为 WebStorm 进行了配置,当我使用 WebStorm 测试运行器运行 Mocha 时,我的测试正在运行。
但是当我从我的终端使用 'node 'the filename'' 运行测试时,出现“未定义描述”的错误。
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
});
});
});
修改我的代码到这个版本后:我收到错误“describe is not a function”。
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
});
});
});
package.json:
{
"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"
}
你能解释一下我需要什么配置才能从终端运行测试吗?
【问题讨论】:
标签: javascript mocha.js webstorm