Node.js 如何将Nock与摩卡咖啡搭配使用
我正在使用nock和mocha进行restapi测试。但是当我使用Node.js 如何将Nock与摩卡咖啡搭配使用,node.js,express,nock,Node.js,Express,Nock,我正在使用nock和mocha进行restapi测试。但是当我使用.reply(200,“msg”:“url matched”)时,它们只检查服务器编码中的200个响应。如何正确使用。 我的代码如下: 这是一个否定的例子。实际上,它们显示了404响应。但是当我使用200时,他们通过了这个测试用例 it("test case for /hotel/:id/location api", function (done) { nock("http://localhost:3010")
.reply(200,“msg”:“url matched”)
时,它们只检查服务器编码中的200个响应。如何正确使用。
我的代码如下:
这是一个否定的例子。实际上,它们显示了404
响应。但是当我使用200
时,他们通过了这个测试用例
it("test case for /hotel/:id/location api", function (done) {
nock("http://localhost:3010")
.get('/hotel/1/location')
.reply(200, {'msg': 'response matched'});
server
.get("/hotel/1/location")
.expect("Content-type", /json/)
.end(function (err, res) {
if (res.success == false) {
res.status.should.equal(200);
}
if (err)
{
res.body.error.should.equal(true);
}
done();
});
nock.cleanAll();
});
});