Unit test a service with http request only angularjs -


I have a function called getFrame in a service. The function only gives the $ http call to the controller

  angular.module ('app') factory ('DemoFactory', function ($ http) {function getFrame (id) {var url = 'http : // localhost: 8080 / frame / '+ id +' / '; return $ http.get (url);} return {getFrame: getFrame};});  

Now I have to write the unittest for this which I am doing:

  Description ('Service: DemoFactory', function () {// Service module beforeEach load; // Instant service $ httpBackend, DemoFactory; beforeEach (Inject (function (_ $ httpBackend_, _DemoFactory_) {$ httpBackend = _ $ httpBackend_; DemoFactory = _DemoFactory_ ;}), This {$ httpBackend.expectGET (function ('must send the proper http request from getFrame',) ('http: // localhost: 8080 / frame / 1 /') .sund (200); DemoFactory.getFrame (1); $ httpBackend.flush ();}); afterEach (function () {$ httpBackend.verifyNoOutstandingExpectation (); $ httpBackend.verifyNoOutstanding Request ();});});  

My goal with the given service is to check whether getFrame is requesting proper HTTP requests. So I think I'm doing fine here. But I was surprised that this block is not expecting any. So I need to confirm that the unit I have been told may be checked for the service I wrote. Is there anything else in the unit test or can I do it any other way?


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -