Questions tagged [httpbackend]

`$httpBackend` is a fake HTTP backend implementation suitable for unit testing applications that use the `$http` service in Angular.js.

$httpBackend is a fake HTTP backend implementation suitable for unit testing applications that use the $http service in Angular.js.

222 questions
19
votes
1 answer

Unexpected request: GET No more request expected at $httpBackend

I have a function in my scope to retrieve the status of my service when the user clicks a button, or when some event are triggered and this function is automatically called. This is my function, defined in the controller I am…
Mimo
  • 6,015
  • 6
  • 36
  • 46
16
votes
2 answers

How can I make $httpBackend insensitive to the order of URL query parameters?

I am using the Angular.js $httpBackend to test some services that wrap $http calls (this is in ngMock, not ngMockE2E). It seems that things like expect and when are sensitive to the order of URL query parameters. E.g. if I do…
13
votes
2 answers

How to use regex in AngularJS $httpBackend ExpectGET

I'm passing a url as a parameter in a $resource GET request. Angular is url encoding this parameter and matching the request in the $httpBackend.expectGET method is finicky. I see that you can use regular expressions to match the expected request…
daddywoodland
  • 1,512
  • 2
  • 12
  • 16
11
votes
1 answer

How do I mock $http in AngularJS service Jasmine test?

I am trying to test an AngularJS service carService, but the $httpBackend does not seem to work. //carService angular.module('services').factory('carService', function($http) { return { getTypes: function() { …
Soni Ali
  • 18,464
  • 16
  • 44
  • 53
11
votes
3 answers

$httpBackend with request with query param

$httpBackend.whenGET('/restpath/api/v1/books') .respond({// some data}); I get the following error Error: Unexpected request: GET /restpath/api/v1/books Expected GET /restpath/api/v1/books?limit=10&start=1 For the expectGET I have the following…
Abhiram mishra
  • 1,597
  • 2
  • 14
  • 34
11
votes
2 answers

Module 'ngMockE2E' is not available! AngularJS

Getting the following error in my browser: Uncaught Error: [$injector:modulerr] Failed to instantiate module sayHiApp due to: Error: [$injector:modulerr] Failed to instantiate module ngMockE2E due to: Error: [$injector:nomod] Module 'ngMockE2E' is…
user818700
10
votes
3 answers

Protractor with Angular Mocks Throws "Window Not Defined"

I've searched around quite a bit on this problem, but can't find a solution. I'm trying to mock my backend, which is well tested so I can completely isolate my frontend. I've tried using protractor-http-mock and also various efforts with…
10
votes
1 answer

Get error when try to use jasmine and angular

When I try to use $httpBackend.flush(); I get error TypeError: $browser.cookies is not a function. I can't find any information about this kind of error and any solutions. describe("someText", function() { var $httpBackend; var someManager; …
gregurco
  • 163
  • 1
  • 7
9
votes
4 answers

How do I expect an HTTP request NOT to be made?

Angular's $httpBackend service lets you expect an HTTP request with expectGET, expectPOST, etc. (or just expect). How would I write a test that says, "the controller should NOT make a request to this endpoint (under these conditions)"? I was…
Dan Tao
  • 125,917
  • 54
  • 300
  • 447
8
votes
1 answer

Testing backend API via $http in AngularJS/karma/jasmine tests?

How do I test my API backend using AngularJS/karma/jasmine tests? I have tried to create the smallest test-case showing my error: echo_server.py from bottle import response, route, run @route('/echo/') def echo_echo(echo): …
A T
  • 13,008
  • 21
  • 97
  • 158
7
votes
3 answers

$httpBackend.flush() method throws Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting

I am trying to unit test my AngularJS application using Karma and Jasmine. I want to mock the $http service. For that, I am using the $httpBackend method. Below is my service that I want to test: angular.module('MyModule').factory('MyService',…
7
votes
1 answer

Print request in httpBackend API mock module in Protractor

I run my e2e tests against a mocked API using angular service $httpBackend in protractor. I already have the debug log of the selenium browser: afterEach(function() { browser.manage().logs().get('browser').then(function(browserLog){ …
louis amoros
  • 2,418
  • 3
  • 19
  • 40
7
votes
1 answer

How to flush AngularJS $httpBackend responses in different order

I have an AngularJS service which performs an $http GET request and caches the response locally. It is designed to handle the multiple calls happening simultaneously, such that only the data from the final call is cached. Specifically, if the…
James Thurley
  • 2,650
  • 26
  • 38
7
votes
3 answers

How to actually reset $httpBackend expectations?

I've tried and tried to get this to work. The documentation is terse, at best: resetExpectations(); - Resets all request expectations, but preserves all backend definitions. Typically, you would call resetExpectations during a multiple-phase test…
FlavorScape
  • 13,301
  • 12
  • 75
  • 117
6
votes
1 answer

AngularJS - What's the point of mocking data via $httpBackend?

I just started writing my first unit tests in AngularJS via Jasmine. Somehow I still do not understand why I should mock the $httpBackend. To make clear what's still unclear to me I will write down a small example: Imagine I have a service…
The_Dude
  • 397
  • 1
  • 3
  • 16
1
2 3
14 15