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!
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.
This is the assert you need (using Jest):
.expect((res) => expect(res.headers['X-Powered-By']).toBeUndefined())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With