Testing the angular project service for specific headers in $ http requests using $ httpBackend, jasmine

I want to check if a specific header is present in the request. This is an article that helped me crack the headlines.

http://jbavari.imtqy.com/blog/2014/06/20/testing-interceptor-headers-in-angularjs/

Below is a snippet from my test. This gives me access to the headers, but the problem is that (it will), it is expected that the headers will be executed when I clear the requests, which does not give 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?

+5
source share
1 answer

A few links helped me.

Testing AngularJs' $ http.defaults.headers.common if a 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(); 
+6
source

Source: https://habr.com/ru/post/1207205/


All Articles