mercredi 24 février 2016

Jasmine Unit test not working for angular service

In the below function I am unit testing get function.

   function httpWrapperService() {
        var self = this;
        self.httpHandler = httpHandler;
        self.get = get;

        function get(url, headers) {
         var config={method:"GET", headers:headers, url:url}
         return httpHandler(config);
        }

        function httpHandler(config)
        {
            // some stuff
        } 
    }

Here is my unit test code using karma

describe('Checking httpWrapperService get() method for different test cases!!!\n', function () {

        it(" Check when url and headers are blank", function (done) {
           spyOn(window, 'httpHandler');

           httpWrapperService.get();
           expect(httpWrapperService.httpHandler).toHaveBeenCalled();
             done();
        });
});  

I tried even window.httpHandler = jasmine.createSpy(); but none of these is working.

What is the mistake I am doing , not able to figure out. I dont want to call httpHandler function.

Any help is appreciated. Thanks

Aucun commentaire:

Enregistrer un commentaire