简体   繁体   English

将Mocha Chai与Node.js错误结合使用:未指定测试

[英]Using mocha chai with Nodejs error: no test specified

I am trying to set up Mocha and Chai for the first time. 我正在尝试首次建立摩卡咖啡和柴。 However, I am getting error message: "No test specified" when I type "npm run test" on the command line. 但是,我在命令行上键入“ npm run test”时收到错误消息:“未指定测试”。 In my package.json file, I have: 在我的package.json文件中,我有:

"scripts": {
    "start": "node server.js",
    "test:":"mocha --compilers js:babel-core/register --require ./test/test_helper.js --recursive"

I have a test folder in my root with two files: 我的根目录中有一个测试文件夹,其中包含两个文件:

// test/testhelper.js

import chai from 'chai';
import chaiImmutable from'chai-immutable';

chai.use(chaiImmutable);

// test/immutablespec.js // test / immutablespec.js

import {expect} from 'chai';

describe('immutability', () => {

    describe('a number', () => {

        function increment(currentState){
            return currentState + 1;    
        }
        it('is immutable',() => {
            let state = 42;
            let nextState=increment(state);

            expect(nextState).to.equal(43);
            expect(state).to.equal(42);

        });
    });
});

The exact message on my console is 我的控制台上的确切消息是

react-hot-boilerplate@1.0.0 test c:\users\owner\react\voting (my root)
echo 'Error:not test specified'

It appears that anything I type in my test script in package.json gets ignored and I get the exact same error msg each time. 似乎我在package.json中的测试脚本中键入的任何内容都将被忽略,并且每次都会得到完全相同的错误味精。

You haven't told mocha where your tests are. 您尚未告诉摩卡您的测试在哪里。 You should point it at your test folder: 您应该将其指向您的test文件夹:

mocha --compilers js:babel-core/register --require ./test/test_helper.js --recursive ./test

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM