I want to check if a specific header is present in the request. This is the article that helped me hack to find the headers.
http://jbavari.github.io/blog/2014/06/20/testing-interceptor-headers-in-angularjs/
The following is the snippet from my test. This is giving me the access to headers but the problem is (will be), it is expecting the headers as a function when I flush the requests, which fails my test implicitly.
$httpBackend
.expect('POST', 'https://www.someurl.com/login',
userObj, function (headers) {
expect(headers['content-type']).toBe('application/x-www-form-urlencoded');
})
.respond();
Any suggestions ?
A couple of links helped me.
Testing AngularJs' $http.defaults.headers.common if specific header is set
http://andrewfong.com/blog/2014/09/22/angularjs-testing-headers-with-whenget-expectget/
$httpBackend
.expect('POST', 'https://www.someurl.com/login',
userObj, function (headers) {
expect(headers['content-type']).toBe('application/x-www-form-urlencoded');
// MUST return boolean
return headers['content-type'] === 'application/x-www-form-urlencoded';
})
.respond();
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