Closed nodesocket closed 7 years ago
Here is a sample for you..
var frisby = require("frisby");
frisby.create("Sample header test case")
.get("http://httpbin.org/response-headers?key=value")
.expectHeader("key",'value') // checks for equality.
.expectHeaderToMatch("key",'') // checks if 'key' exists & matches the pattern ''
.expectHeaderToMatch("key",'lue') // checks if 'key' exists & matches the pattern 'lue'
.after(function(err,res,body){
console.log(res.headers);
expect(res.headers.key).toBeDefined();
expect(res.headers.otherkey).not.toBeDefined();
expect(res.headers.hasOwnProperty('key')).toBe(true);
expect(res.headers.key).toEqual(jasmine.any(String));
expect(res.headers.key).not.toEqual(jasmine.any(Number));
expect(res.headers.key).not.toEqual(jasmine.any(Object));
expect(res.headers.key).toMatch('');
})
.toss();
expectHeaderExists("headerKey")
. It is not available.
You could use .expectHeaderToMatch("headerKey",'')
for now.
However, HEADERKEY / headerKEY mean the same as it converts to lowercase before verifying.~ Sasi
Thanks. expectHeaderExists('X-Foo-Bar')
would be useful. Maybe worth adding in.
Frisby v2 has a use-case for this. If you only supply a single argument, it only checks for the header's existence: .expect('header', 'X-Foo-bar')
.
How can I assert that a header exists, but I don't care about the value? I.E. only care that the header key exists.
Thanks.