我在一个当前没有测试过的函数中有一个分支.它是来自请求操作的错误处理程序(使用同名的节点模块).这是特定的行: request(url, function (error, response, body) { if (error) return cb(error); 这是测
request(url, function (error, response, body) {
if (error) return cb(error);
这是测试:
describe("handles errors", function() {
it("from the request", function (done) {
var api = nock('http://football-api.com')
.get('/api/?Action=today&APIKey=' + secrets.APIKey + '&comp_id=1204')
.reply(500);
fixture.getFixture(FixtureMock, function (err, fixture) {
expect(err).to.exist
done();
});
});
规格失败:
Uncaught AssertionError: expected null to exist
因此,发送500状态代码作为没有正文的响应不会导致请求回调中的错误,或者我正在测试错误的东西.
使用doc中的replyWithError:nock('http://www.google.com')
.get('/cat-poems')
.replyWithError('something awful happened');
