I started unit testing to existing Angular/ionic App i have install karma and jasmine. I wrote the first unit test for a service but it fail and got this error:
Error: [$injector:unpr] Unknown provider: followServiceProvider <- followService
I wonder if my injecting way is correct! To make sure my setup is fine i started new ionic app installed karma and jasmine tried simple test and it worked
Here is the code of the service followService:
'use strict';
angular.module('myApp.services')
.factory('followService', function($http, $q, API_URL) {
var url = API_URL + 'api/users/followers' ;
function getFollowers() {
var deferred = $q.defer();
$http.put(url)
.success(function(data, status, headers, config) {
deferred.resolve(data);
})
.error(function(data, status, headers, config) {
deferred.reject(data);
});
return deferred.promise;
}
});
And this the unit test for it :
'use strict';
describe('Service: followService Test Follow APIs', function () {
// load the service's module
beforeEach(module('myApp.services'));
// instantiate service
var followService;
var $httpBackend;
beforeEach(inject(function (_$httpBackend_, _followService_) {
followService = _followService_;
$httpBackend = _$httpBackend_;
}));
it('should GET Followers from the server', function () {
$httpBackend.expectGET('api/users/followers').respond(200, {"id": "55d1c1acddb6dabe468bbba1", "displayName": "Brand1", "pictrue": "path/to/picture"});
var followers = followService.getFollowers();
$httpBackend.flush();
expect(followers).not.toBe(null);
});
});
Aucun commentaire:
Enregistrer un commentaire