0

Why does Nock give me an error saying that bodies don't match??

here is my code.

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();
    });

  });

I get this response when I use the .log

I have no clue why it tells me bodies dont match. I get this specifically.

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"                                     
}                                                                                          
user3450754
  • 115
  • 1
  • 1
  • 12

1 Answers1

2

There is an open issue at github that you currently are not able to use .delete(url, data).

But you can fix it easily like this:

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();
 });

If you call .send(data) instead of passing data into .delete method it works just fine.

Antonio Narkevich
  • 4,206
  • 18
  • 28