Testing angular $resource with Jasmine

Testing angular $resource with Jasmine

HTML

<script src="http://jasmine.github.io/1.3/lib/jasmine.js"></script>
<script src="http://jasmine.github.io/1.3/lib/jasmine-html.js"></script>
<link rel="stylesheet" href="http://jasmine.github.io/1.3/lib/jasmine.css">
<script src="http://code.angularjs.org/1.2.9/angular.js"></script>
<script src="http://code.angularjs.org/1.2.9/angular-mocks.js"></script>
<script src="https://code.angularjs.org/1.2.9/angular-resource.js"></script>

JavaScript

//--- CODE --------------------------
(function (angular) {
    angular.module('userApp', ['ngResource'])
    .factory('UserService', function($resource) {
        return $resource('../banques', {},{
            'search': {
                method: 'GET',
                params: {
                    codeBanque : '@codeBanque',
                    codeGuichet: '@codeGuichet',
                    bic:'@bic',
                    denoBanque:'@denoBanque',
                    departement:'@departement',
                    pageSize:'@pageSize',
                    numeroPremierElement:'@numeroPremierElement'
                }
            }
        });

});
})(angular);

// ---SPECS-------------------------
describe('userApp', function () {
    var UserService
      
    ;
    
    beforeEach(function () {
        module('userApp');
    });
    
    beforeEach(inject(function (_UserService_, _$httpBackend_) {
        UserService = _UserService_;
        $httpBackend = _$httpBackend_;
    }));

    describe('User resource - api/users', function () {
        it('Calls GET – api/users/{id}', function() {
            $httpBackend.expectGET('../banques?codeGuichet=000000').respond(200);
            
            UserService.search({codeGuichet:"000000"});
            
            $httpBackend.flush();
        });
        
    });
});

// --- Runner -------------------------
(function () {
    var jasmineEnv = jasmine.getEnv();
    jasmineEnv.updateInterval = 1000;

    var htmlReporter = new jasmine.HtmlReporter();

    jasmineEnv.addReporter(htmlReporter);

    jasmineEnv.specFilter = function (spec) {
        return htmlReporter.specFilter(spec);
    };

    var currentWindowOnload = window.onload;

    window.onload = function () {
        if (currentWindowOnload) {
            currentWindowOnload();
        }
        execJasmine();
    };

    function execJasmine() {
        jasmineEnv.execute();
    }

})();