我正在使用Mocha运行单元测试,而不是在报告器中显示所有抛出的AssertionErrors Mocha在第一个错误时崩溃.有什么建议?
我在崩溃时遇到的错误是这样的:
/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还是内置断言库,它都是一样的.我用这个命令运行Mocha(我用npm测试运行它):
mocha --reporter 'spec' --recursive
我正在使用的库版本是:
>节点:0.10.18
>摩卡:1.12.0
>柴:1.8.0
> hapi:1.10.0
测试代码:
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(); }); }); }); });