I am trying to run a unit test on my AngularJS application using Karma and Jasmine. I want to mock the $ http service. For this, I use the $ httpBackend method. Below is my service that I want to check:
angular.module('MyModule').factory('MyService', function($http, $log, $parse, $q, $timeout, $filter, MyOtherService1, MyOtherService2){ var service = {}; service.getSomething = function(id){ return $http.get('/somePath/subpath/' + id); } });
My unit test for this service:
describe("myTest", function(){ var myService, $httpBackend, scope, mockMyOtherService1, mockMyOtherService2; var myResponse = { foo:'bar' }; beforeEach(module("MyModule")); beforeEach(inject(function(_MyService_, $injector){ $httpBackend = $injector.get('$httpBackend'); myService = _MyService_; scope = $injector.get('$rootScope').$new(); mockMyOtherService1 = $injector.get('MyOtherService1'); mockMyOtherService2 = $injector.get('MyOtherService2'); })); beforeEach(function(){
This is an extreme problem and I need help regarding the same as soon as possible. I will be very grateful for your reply.
source share