我如何用 nock 模拟删除
这是我到目前为止所做的:
var nock = require('nock');
var request = require('supertest')("http://localhost:8080");
var expect = require('chai').expect;
describe('Mocked tests for server components', function(){
var mockRequest = nock('http://localhost:8080');
it('Should Delete /user/removeuserskills', function(req, res){
mockRequest
.delete('/user/removeuserskills',{
'email':'Johny@gmail.com',
'user_skill':'accoutant'
})
.reply(200,{
'status':200,
'message': '200: Successfully deleted skill'
});
request
.delete('/user/removeuserskills')
.end(function(err, res){
expect(res.body.status).to.equal(200);
});
});
});
我无法演示如何首先添加具有该技能的用户,然后将其删除。
现在使用此代码,我得到一个未定义的主体。
编辑:
其实我得到
{ Error: Nock: No match for request:
{ method:"DELETE",
url: "http://localhost:8080/user/removeuserskills"
}
}