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
6
votes
2 answers

Multiple sequential httpBackend requests cause unexpected request

I'm testing a sequence that polls a resource until a condition is met. Book = $resource("/books/:id", {id: "@id"}); function poll(success) { Book.get({id:1}, function() { if (canStop) { success(); } else { $timeout(poll,…
ChrisJ
  • 2,486
  • 21
  • 40
6
votes
3 answers

Make $httpBackend ignore any requests made to server

I have the following controller (notice that at instantiation time I make an explicit call to $scope.getNotifications()): bla.controller("myctrl", [ "$scope", "$http", "configs", function ($scope, $http, configs) { …
Liviu Mandras
  • 6,540
  • 2
  • 41
  • 65
6
votes
2 answers

Unit testing AngularJS with $httpBackend gives "Error: Unexpected Request"

I'm gonna preface this question by saying I've already gotten a test to work for my "LoginCtrl" which performs almost the exact same task. I'm sure this is an issue of something really small I've overlooked. Thanks in advance for any help :) I've…
robert.bo.roth
  • 1,343
  • 3
  • 14
  • 24
5
votes
0 answers

mock HTTP requests of Angular2/4 using protractor/cucumber

I am trying to automate an angular 4 application.(protractor, cucumber, typescript). Stuck at mocking the HTTP requests. Found Couple of approaches: 1) httpBackend 2) http-backend-proxy But all of them talks about AngularJs application. And as per…
Vinni
  • 569
  • 1
  • 8
  • 18
5
votes
2 answers

Failed: $httpBackend.whenGET is not a function

whenGET is not a function but when I output the proxy var I cleary see that the function is there { when: [Function], whenGET: [Function], whenPUT: [Function], whenHEAD: [Function], whenPOST: [Function], whenDELETE: [Function], …
San Jay Falcon
  • 993
  • 1
  • 9
  • 20
5
votes
0 answers

No pending request to flush on using whenGET, but not expectGET

When testing an angular service using $httpBackend I get some unexpected results. When I run the test using httpBackend.expectGET the test works as expected. However if I run the exact same test using whenGET the test fails with the message 'No…
Daltin
  • 91
  • 6
5
votes
1 answer

AngularJS testing: Mocking $httpBackend - Handling Success and Error Methods

Update: I managed to further narrow down the problem scope and fix the Unexpected request error by updating the httpBackend.when request which contained some invalid ascii characters. I have attached a Plunker witht he current code block. But I am…
5
votes
1 answer

Is there an example of AngularJS app generated by Yeoman with e2e tests and $httpBackend?

Is there somewhere an example of AngularJS app generated by yo angular generator that has e2e tests with $httpBackend from ngMockE2E module? Preferably with single and continuous versions for CI and development. It looks like using $httpBackend…
szimek
  • 6,404
  • 5
  • 32
  • 36
4
votes
1 answer

Node Js make call to http python flask server

I have a machine learning model, I have made an API out of it, and hosted a flask server to make it accessible as such server = '192.168.71.53' port = 5000 app = Flask(__name__) app.config['CORS_HEADERS'] = 'Content-Type' cors = CORS(app,…
Imtinan Azhar
  • 1,725
  • 10
  • 26
4
votes
0 answers

Puppet clients applying empty classes (with default parameters)

The problem: Servers running puppet agent in my environment are receiving empty [classes] (without parameters), instead of the expected parameters stored in their Hiera document. This causes puppet modules to run with null parameters which in turn…
Oz Bar-Shalom
  • 1,747
  • 1
  • 18
  • 33
4
votes
0 answers

Angular ngmock httpBackend - ignore all but one request?

I am new to writing unit tests, so apologies if this is a dumb question. If I'm trying to test a method in an Angular controller that relies on mock data from a service call, and I want to also mock that service call (ngResource), is there a way to…
Jasman
  • 143
  • 1
  • 10
4
votes
1 answer

AngularJS & Karma-Jasmine - Not working if verifyNoOutstandingExpectation(); or verifyNoOutstandingRequest(); stands alone

I have one http request that has not been flushed, so when I have it like this afterEach(function(){ $httpBackend.verifyNoOutstandingExpectation(); $httpBackend.verifyNoOutstandingRequest(); }); It works as expected and I get Error:…
Stevik
  • 1,092
  • 2
  • 16
  • 37
4
votes
1 answer

How to mock jquery ajax call while testing angular page

I'm writing e2e test for my angular page with protractor. I use $httpBackend for mocking requests which are sent by $http But in one old page i found jquery ajaxFrom plugin which sends call by jquery ajax. I noticed that it couldn't be mocked by…
VladJS
  • 393
  • 1
  • 3
  • 12
4
votes
2 answers

AngularJS unit testing. HttpBackend

I have AngularJS app with unit tests covering it. I added one more http request in .run part of application which checking user authentication. Now about 60% of my tests fails because they found 'unexpected http request'. Even directives tests are…
Fyodor Khruschov
  • 1,657
  • 7
  • 23
  • 40
4
votes
1 answer

$httpBackend.flush() still needs timeout for defining objects

I am unittesting my AngularJS app with Karma and stubbing the backend with $HttpBackend. Somehow, the flush() method does not seem to resolve all my requests as some of the variables in the controller still remain undefined. However, if I add a…
M Jacobs
  • 251
  • 1
  • 3
  • 9
1
2
3
14 15