首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Nock -Nock不匹配

Nock -Nock不匹配
EN

Stack Overflow用户
提问于 2017-03-04 14:37:40
回答 1查看 1.1K关注 0票数 0

为什么Nock给我一个错误,说身体不匹配??

这是我的代码。

代码语言:javascript
复制
it('Should Delete /user/removeuserskills', function(done){

    mockRequest
    .delete('/user/removeuserskills',{skill:'accountant'})
    .reply(201,{
      'status':200,
      'message': '200: Successfully deleted skill'
      })
    .log(console.log)
    request
    .delete('/user/removeuserskills',{skill:'accountant'})
    .end(function(err, res){
      if(err){
        console.log(err);
      }
      else{
      expect(res.body.status).to.equal(200);
      expect(res.body.message).to.equal('200: Successfully deleted skill');}
      done();
    });

  });

当我使用.log时,我得到以下响应

我不知道为什么它告诉我身体不匹配。我特别明白这一点。

代码语言:javascript
复制
matching http://localhost:8080 to DELETE http://localhost:8080/user/removeuserskills: true 
bodies don't match:                                                                        
 { skill: 'accountant' }                                                                   

{ Error: Nock: No match for request {                                                      
  "method": "DELETE",                                                                      
  "url": "http://localhost:8080/user/removeuserskills"                                     
}                                                                                          
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-04 16:43:41

在github上有一个你当前不能使用.delete(网址,数据)的open issue

但是你可以像这样很容易的修复它:

代码语言:javascript
复制
mockRequest
	.delete('/user/removeuserskills', {skill: 'accountant'})
	.reply(201, {
		'status': 200,
		'message': '200: Successfully deleted skill'
	})
	.log(console.log)

request
	.delete('/user/removeuserskills')
	//Just call .send here instead
	.send({skill: 'accountant'})
	.end(function (err, res) {
		...
		done();
	});

如果调用.send( data )而不是将数据传递给.delete方法,它就能正常工作。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42592970

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档