Node.js 使用带有Nodejs的mocha chai错误:未指定测试
我第一次尝试建立摩卡和柴。但是,当我在命令行上键入“npm run test”时,会收到错误消息:“未指定测试”。在我的package.json文件中,我有:Node.js 使用带有Nodejs的mocha chai错误:未指定测试,node.js,mocha.js,chai,chai-immutable,Node.js,Mocha.js,Chai,Chai Immutable,我第一次尝试建立摩卡和柴。但是,当我在命令行上键入“npm run test”时,会收到错误消息:“未指定测试”。在我的package.json文件中,我有: "scripts": { "start": "node server.js", "test:":"mocha --compilers js:babel-core/register --require ./test/test_helper.js --recursive" 我的根目录中有一个测试文件夹,其中包含两个文件: /
"scripts": {
"start": "node server.js",
"test:":"mocha --compilers js:babel-core/register --require ./test/test_helper.js --recursive"
我的根目录中有一个测试文件夹,其中包含两个文件:
// test/testhelper.js
import chai from 'chai';
import chaiImmutable from'chai-immutable';
chai.use(chaiImmutable);
//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);
});
});
});
我控制台上的确切信息是
react-hot-boilerplate@1.0.0 test c:\users\owner\react\voting (my root)
echo 'Error:not test specified'
似乎我在package.json的测试脚本中键入的任何内容都会被忽略,每次我都会收到完全相同的错误消息。您还没有告诉mocha您的测试在哪里。您应该将其指向您的
test
文件夹:
mocha --compilers js:babel-core/register --require ./test/test_helper.js --recursive ./test
仍然收到相同的错误消息。即使我在脚本测试中输入gibberish,它似乎被忽略了,我得到了相同的消息。当我键入npm start时没有问题,但是npm run test有问题。直接在命令行中运行我建议的命令。它在package.json之外工作吗?是的,它在命令行中工作。所以我现在的问题是,为什么我的package.json中没有读取测试脚本。即使npm启动脚本运行良好。oops,也请忽略这一点。打字错误-我有两个冒号。谢谢顺便说一句,没有必要指定./test。Mocha仍然设法找到了测试文件。