Angular mock $httpBackend give No pending request to flush Angular mock $httpBackend give No pending request to flush angularjs angularjs

Angular mock $httpBackend give No pending request to flush


The _$httpBackend_ has nothing to flush because you don't make any http request in your test.

You need to invoke some code that make an http request.

Then, once something somewhere made an http request in your test, you can call the flush method so that a response is provided for the request that has been made.

Something like:

it('should fetch list of users', function(){    // Do something that will make an http request    MyService.getAllUser(function ...) // for example    // Then provide a response for the http request that     // has been made when getAllUser was called    $httpBackend.flush();    // Check the expected result.    expect(something).toBe('Bob');});


Same issue happened to me and the problem was not that I was not making a request but because the request I was making was different to the expected one:

For example I have defined this expectation:

mockBackend.expectGET("http://myapi.com/001").respond("RESULT");

And I was requesting this other URL:

http://myapi.com/002

Very confusing error message, no really easily related with the underneath problem.


I had the same issue, because I neglected to define a response for each expected request. With no response, there becomes nothing to flush. Also the http promise would never resolve or fail.