vendredi 22 mai 2015

Service is not defined while testing for angular service using karma/jasmine

I am trying run following test case using karma.

'use strict';

describe('companyService', function () {

var $httpBackend, companyService;

beforeEach(module('MyCompany'));

beforeEach(inject(function (_$httpBackend_, _companyService_) {
    $httpBackend = _$httpBackend_;
    companyService = _companyService_;
}));

it('should return a promise for getCompany function', function () {
    expect(typeof companyService.getCompany('foobar').then).toBe('function');
});

});

Following is the Companyservice.js

angular.module('finale').factory('companyService',
function($http, MyCompanyApiProvider, $upload) {
    'use strict';

    var _company = null;

    function getCompany(companyId) {
        var x = $http.get(MyCompanyApiProvider.url('companies/' + companyId));
        return x;
    }

return { getCompany: getCompany

};

});

I get an error saying companyService is undefined just before calling getcompany method . what am i missing here ?

Aucun commentaire:

Enregistrer un commentaire