I am trying to test my $http request using karma and jasmine.I make one controller and inject a service .In service I call $http service.I need to test that service how I will test this service this is my controller.
angular.module('app',[]).controller('first',function($scope,data){
$scope.name='test';
data.getData().then(function(data){
console.log(data);
})
}).factory('data',function($http){
return{
getData:getData
}
function getData(){
return $http.get('data.json').success(successCall).error(errorcallback)
}
function successCall(data){
return data
}
function errorcallback(data){
return data
}
})
here is plunker http://plnkr.co/edit/POryyDUc8bvvfvI5Oap7?p=preview
i start like this
describe('http controller test', function () {
var $rootScope,
$scope,
controller;
beforeEach(function(){
module('app') ;
inject(function($injector){
$rootScope = $injector.get('$rootScope') ;
$scope=$rootScope.$new();
controller =$injector.get('$controller')('first',{$scope:$scope})
})
})
describe('Init value',function(){
it('check name value',function(){
expect($scope.name).toEqual('test');
})
})
it('it should be true',function(){
expect(true).toBeTruthy();
})
})
could you please tell me how to write test when there is dependency of service in controller ?? how to test $http request in jasmine?in my controller there is a dependency of a service .how to inject this in my test file?