9

If I set the express.js like this:

app.set("x-powered-by", false);

How to test this?

.expect('X-Powered-By', '', done)

will throw error: Error: expected "X-Powered-By" header field

.expect('X-Powered-By', null, done)

also not works.

Thanks!

HaveF
  • 2,995
  • 2
  • 26
  • 36

2 Answers2

8

This is the assert you need (using Jest):

.expect((res) => expect(res.headers['X-Powered-By']).toBeUndefined())

MEMark
  • 1,493
  • 2
  • 22
  • 32
6

I would suggest creating custom validation as follows:

it('should validate header is not present.', function(done){
  request
    .get('/path/to/your/resource')
    .end(function(error, response){
      if (error) {
        return done(error);
      }
      // Here is where we identify is header exists or not
      var isHeaderPresent = response.header['header-to-validate'] !== undefined;
      isHeaderPresent.should.be.False();
      done();
    });
});

Note also that this example uses should library for its validations.

leo.fcx
  • 6,137
  • 2
  • 21
  • 37
  • thanks, leo, btw, do you know why this kind of api is not part of supertest? just because few people need it? or I use the wrong paradigms? – HaveF Oct 19 '15 at 22:05
  • Probably because it is not a common use case. At least, I did not face that case before. – leo.fcx Oct 20 '15 at 04:17