4

I am trying to write some Supertest test cases where the User-Agent header is sent with a value, blank, or not at all.

I know I can use .set to handle setting a value for that header or '' for blank, but I am not sure how to omit the User-agent header completely. If I leave it off the request supertest sends a default value of node-superagent/1.2.0. If I .set('User-agent', null) it sends 'null' over the wire.

There doesn't appear to be a .remove or .delete. Anyone have an idea?

it ('example', function(done){
  agent.post('/abc/a')
  .set('User-agent', 'some agent')
  .send('abc')
  .expect(200)
  .end(function(err, results){})
};
EdgeCase
  • 135
  • 2
  • 12

1 Answers1

7

The method is called .unset(). You can use as follows:

it ('example', function(done){
  agent.post('/abc/a')
  .unset('User-Agent')
  .send('abc')
  .expect(200)
  .end(function(err, results){})
};
JME
  • 3,592
  • 17
  • 24