angularjs - Angular JS Unit Testing $httpBackend spec has no expectations -


i have unit test in expectation http call made. use $httpbackend.expect() this. works fine, , unit test fails if http request not made (which good), , passes if http request made.

the problem thought passes, jasmine spec runner shows "spec has no expectations" unit test, makes me think not using recommended way test http call made. how avoid seeing message?

example test:

it('should call sessioncheck api', function () {     inject(function ($injector, sessiontrackerservice) {         $httpbackend = $injector.get('$httpbackend');          var mockresponse = { isauthenticated: true, secondsremaining: 100 };         $httpbackend.expect('get', 'api/authentication/sessioncheck')             .respond(200, mockresponse);          sessiontrackerservice.start();          jasmine.clock().tick(30001);         $httpbackend.flush();     }); }); 

i wrap call flush follows:

expect($httpbackend.flush).not.tothrow(); 

i prefer approach because test code states 'should' happen when flush called. example:

it('should call expected url', inject(function($http) {     // arrange     $httpbackend.expectget('http://localhost/1').respond(200);      // act     $http.get('http://localhost/1');      // assert     expect($httpbackend.flush).not.tothrow();  })); 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -