摩卡没有显示所有的testing

我有一些摩卡unit testing,当我运行这些只有2/3的testing显示。 我正在使用斑点记者,并通过运行我的testing。

这是我的makefile:

REPORTER = list TESTS = test/*.js test/**/*.js test/**/**/*.js REQUIRE = should test: @NODE_ENV=test NODE_PATH=./app/controllers ./node_modules/.bin/mocha \ --reporter $(REPORTER) \ --ui tdd \ --require $(REQUIRE) \ -G \ $(TESTS) test-ci: @NODE_ENV=ci NODE_PATH=./app/controllers ./node_modules/.bin/mocha \ --reporter $(REPORTER) \ --ui tdd \ --require $(REQUIRE) \ $(TESTS) start: NODE_PATH=./app/controllers NODE_ENV=development nodemon server.js .PHONY: test 

test/test.js

 /*! * Module dependencies. */ var request = require('supertest') var app = require('../server') var mongoose = require('mongoose') var config = require('../config/config')[process.env.NODE_ENV]; // other stuff you want to include for tests function clearDB(done) { (function(done) { var index = 0; var models = mongoose.modelNames(); function deleteModel(err) { if (err) { return done(err) }; if (index == models.length) { return done() }; mongoose.model(models[index]).remove({}, deleteModel); index++; } deleteModel(); })(done) } before(function(done) { this.timeout(0) clearDB(done); }) function populateDatabase(Functions, done) { Func = mongoose.model("KIFunction"); var functions = 0; if (typeof Functions == 'function') { done = Functions Functions = 20 } function addFunction(err) { if (err) { done(err); } if (functions < Functions) { functions++; var func = new Func({ string: ("n*" + functions), approved1: true, approved2: true, approved: true, }).save(addFunction); } else { done(); } } addFunction(); } describe('Functions', function() { describe('GET /functions/get', function() { it('Should be text/kinoki-function', function(done) { this.timeout(0) populateDatabase(11, function(err) { if (err) done(err) request(app) .get("/functions/get") .query('n=[]') .expect('Content-Type', new RegExp("kinoki-function")) .expect(200) .end(function(err, res) { if (err) return done(err) else done() }) }) }) it('Should have 10 functions', function(done) { this.timeout(0) populateDatabase(25, function(err) { if (err) return done(err) request(app) .get("/functions/get") .query('n=[]') .expect(200) .end(function(err, res) { var body = res.text body.split("|").length.should.equal(10) if (err) return done(err) done() }) }) it('Each Of Them Should Match The Function Pattern', function(done) { this.timeout(0) populateDatabase(11, function(err) { if (err) return done(err) request(app) .get("/functions/get") .query('n=[]') .expect(200) .end(function(err, res) { var body = res.text body.split("|").forEach(function(func) { func.should.match(/[0-9]#n([+\-*\/][0-9]+)+#(Easy|Medium|Hard|Deadly)+#[0-9a-fA-F]{24}/) }) if (err) return done(err) done() }) }) }) it('Should return \'false\' when there are no functions', function(done) { this.timeout(0) clearDB(function(err) { if (err) done(err) request(app) .get("/functions/get") .query('n=[]') .expect(200) .end(function(err, res) { if (err) return done(err) res.text.should.equal("false") done() }) }) }) it('Should NOT throw an error when no array of functions to exclude is in the querystring', function(done) { this.timeout(0) clearDB(function(err) { if (err) done(err) request(app) .get("/functions/get") .end(function(err, res) { if (err) return done(err) res.status.should.not.equal(500) res.status.should.equal(200) done() }) }) }) }) describe("POST /functions/submit", function() { this.timeout(0) it("Should NOT be a 404", function(done) { request(app) .post("/functions/submit") .end(function(err, res) { if (err) return done(err) res.status.should.not.equal(404) done() }) }) it("Should be a 400 (Bad Request) without querystring", function(done) { request(app) .post("/functions/submit") .end(function(err, res) { if (err) return done(err) res.status.should.equal(400) done() }) }) }) }) }) after(function(done) { // do some stuff done() }) 

这是摩卡的输出:

03:48 PM Kinoki-Server Ari $ make test在端口9273上启动应用程序

函数GET /函数/ get✓应该是文本/ kinoki函数(67ms)✓应该有10个函数(76ms)POST /函数/提交✓不应该是404✓应该是没有查询string的400

4传球(224毫秒)

03:52 PM Kinoki-Server Ari $

它说4通过,但我有6个testing! 为什么摩卡隐藏其他testing?

我的猜测是,当你直接嵌套调用互相之间,摩卡并没有得到他们正确的登记。 坚持每一个调用it的模式必须直接在一个describecallback,看看是否修复它。