AssertionError崩溃摩卡

我正在使用摩卡进行unit testing,而不是显示记者摩卡崩溃的第一个错误的所有抛出的断言错误。 有什么build议么?

我碰到的错误是这样的:

/Users/Robert/Code/JRJ/Server/node_modules/chai/lib/chai/assertion.js:106 throw new AssertionError(msg, { ^ AssertionError: expected 200 to equal 202 npm ERR! weird error 8 npm ERR! not ok code 0 

无论是使用Chai还是内置的assert库,都是一样的。 我用这个命令运行Mocha(我用npm test运行它):

 mocha --reporter 'spec' --recursive 

而我正在使用的库版本是这些:

  • 节点:0.10.18
  • 摩卡:1.12.0
  • 柴:1.8.0
  • hapi:1.10.0

testing代码:

  var hapi = require('hapi'), expect = require('chai').expect, assert = require('assert'); describe("Customer API", function(){ var server = require('../../../../src/apis/customer'); //works as expected describe('simpleExample', function(){ it("should cause a test failure", function(done){ expect(200).to.equal(202); done(); }); }); //crashes Mocha describe('Authentication', function(){ it('Should get user token', function(done){ server.inject("/auth?username=test@test.com&password=testa", function(res){ expect(res.statusCode).to.equal(202); //returns 200, crashes Mocha (the expected 202 is intentional to cause an assertion error) //assert.ok(res.statusCode === 202); expect(res.payload).to.be.a('string'); expect(res.payload).to.have.length(16); done(); }); }); }); }); 

这是因为这是摩卡工作的方式。 asynchronous调用中的exception需要被捕获并传递给完成的callback,甚至包括AssertionErrors。 在摩卡文档中有一个错误,我已经打开一个GitHub问题来解决这个问题( https://github.com/visionmedia/mocha/issues/982 )。