lundi 30 novembre 2015

Angularjs+ jasmine test returns zero length

I'm calling a service in my unit test. The service seems to be available and the method is defined. I've created and spy and when I call the method I'm not receiving errors. When I try to access the response of the service call I get zero length (there are 2 records).

What am I missing?

describe("can I initialise the object  ", function () {
        var myMethodToCallDataService;

        beforeEach(function(){
            module(moduleName);
            module('services');
            inject(function($injector, _$controller_, _$rootScope_){
                $controller = _$controller_;
                $rootScope = _$rootScope_;
                myMethodToCallDataService = $injector.get('myMethodToCallDataService');
            });
        });

        it("myMethodToCallDataService should be defined", function () {
            expect(myMethodToCallDataService).toBeDefined();
        });

        it("myMethodToCallDataService should call the mt", function () {
            scope = $rootScope.$new();
            spyOn( myMethodToCallDataService, 'myMethodToCall' );
            myMethodToCallDataService.myMethodToCall();
            expect(myMethodToCallDataService.myMethodToCall).toHaveBeenCalled();
            scope.$apply();
            expect(myMethodToCallDataService.myMethodToCall.length).toBeGreaterThan(1);
        });
    });

Aucun commentaire:

Enregistrer un commentaire