Javascript 如何使用WebStorm配置Mocha

Javascript 如何使用WebStorm配置Mocha,javascript,mocha.js,webstorm,Javascript,Mocha.js,Webstorm,我对运行摩卡测试有意见 我为WebStorm进行了配置,当我使用WebStorm测试运行程序运行Mocha时,我的测试正在运行 但是当我从我的终端运行文件名为“node”的测试时,我得到了错误“descripe is not defined” 在将我的代码修改为这个版本后:我得到了错误“描述不是函数” package.json: 您能解释一下,为了从终端运行测试,我需要什么配置吗?您需要使用mocha test runner来运行您的测试,只需将测试文件传递给节点解释器就行了 只需将“test”

我对运行摩卡测试有意见

我为WebStorm进行了配置,当我使用WebStorm测试运行程序运行Mocha时,我的测试正在运行

但是当我从我的终端运行文件名为“node”的测试时,我得到了错误“descripe is not defined”

在将我的代码修改为这个版本后:我得到了错误“描述不是函数”

package.json:
您能解释一下,为了从终端运行测试,我需要什么配置吗?

您需要使用mocha test runner来运行您的测试,只需将测试文件传递给节点解释器就行了

只需将
“test”:“mocha”
添加到
包.json的
“scripts”:{}
部分,然后在终端中运行
npm test


请参见

您需要使用mocha test runner来运行您的测试,只需将测试文件传递给节点解释器就行不通了

只需将
“test”:“mocha”
添加到
包.json的
“scripts”:{}
部分,然后在终端中运行
npm test

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"
}