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
3
votes
1 answer

Haproxy logging final path after rewrite rule is processed

In Haproxy 1.8.8, I am trying to log the final URI (not the incoming URI that was received in the frontend), In the backend section, i have proxy rewrite rule to change the path. I want that new path to be in the haproxy log. Here is the sample…
DevOpsNewB
  • 185
  • 2
  • 14
3
votes
1 answer

Error: Unflushed requests Karma

Attempting to mock an http call but getting the error Error: Unflushed requests: 1 in /Users/..etc/angular-mocks.js here is my relevant code describe('Tests for Group Controller', function() { var $httpBackend; beforeEach(function() { …
ceckenrode
  • 4,543
  • 7
  • 28
  • 48
3
votes
1 answer

setting proxy or backend URL while doing gulp build:dist

We have some code in Angular JS which is build using gulp (babel). We have necessity to redirect the api service calls to a different server. Hence, which development we run gulp server and with that add the api-host server in the proxy argument…
indranil9286
  • 81
  • 2
  • 10
3
votes
2 answers

$httpBackend: Angular Unit-Testing that a GET request is sent

I'd like to test that a (component's) controller is sending a GET request to some URL (without caring about the response). I was expecting that httpBackend.expectGET('/some/random/url'); would spy on the http backend and fail if it did not get the…
sunless
  • 597
  • 5
  • 19
3
votes
0 answers

AngularJS $httpBackend asynchronous response

I'm trying to mock the back-end for an AngularJS(1.3.8)-app with ngMockE2E as replacement until the back-end code has been written. I'm using already existing services that also query other data, however they return a promise. I am aware that…
3
votes
0 answers

$httpBackend doesn't respond in Protractor test

I'm trying to write a test in Protractor/Jasmine that depends upon my being able to see the headers sent in an HTTP request. To that end I'm trying to create a mock endpoint with $httpBackend that will respond to a call with the headers themselves,…
Nat Webb
  • 669
  • 1
  • 7
  • 18
3
votes
1 answer

jasmine karma unit test "Error: Unexpected request: GET /Content/json/3420_layer0.json"

Writing a simple test case. describe('Services', function () { describe('API', function () { var $httpBackend, $rootScope, createController, requestHandler; var jsonLayer0 = "/Content/json/3420_layer0.json"; // Set up…
ganjan
  • 7,356
  • 24
  • 82
  • 133
3
votes
2 answers

HAProxy and reqrep path rewriting with redirect configuration

With HA Proxy 1.5 I need to rewrite URL from http://main.domain.com/my-foo to http://othersite.com:8081/other-bar Here is what I tried: frontend ft_def bind :80 mode http …
djool
  • 48
  • 1
  • 4
3
votes
1 answer

Add multiple mock modules in one test with 'addMockModule'

I'm mocking some end-points on an Angular website with Protractor using the following pattern: // mock.js // adding the mock module and passing it data Mock.prototype.all = { default: function() { browser.addMockModule('httpBackendMock',…
magicode118
  • 1,444
  • 2
  • 17
  • 26
3
votes
3 answers

AngularJS & Karma-Jasmine - $httpbackend flush only if there is one or more pending requests

Is it possible to call $httpbackend.flush(); only if there are some pending request ? So I will never get Error: Unflushed requests: 1,2,3,...,n Or Error: No pending request to flush !
Stevik
  • 1,092
  • 2
  • 16
  • 37
3
votes
1 answer

Angular test using $httpBackend fails with "400 thrown" error

For hours I've been trying to test my NewPostController with $httpBackend. The problem is whenever I set non-2xx status code in the response, the test fails. NewPostController has the following method: $scope.submit = function () { var newPost =…
3
votes
1 answer

Unexpected Request Error with $HttpBackend (AngularJS)

I am using HttpBackend to mock some Http responses for some calls that my Angular app is making. However, I am getting the error "Unexpected Request: [object Object] undefined" when I run my tests. I know that usually this error means you're missing…
3
votes
0 answers

$httpBackend.verifyNoOutstandingExpectation is useless?

I noticed strange thing while trying to unit test one of my controllers with karma. Here is spec: it 'should POST new category data to /api/categories with category name', -> $httpBackend.expectGET '/api/categories' .respond 200, '' …
dKab
  • 2,658
  • 5
  • 20
  • 35
3
votes
1 answer

AngularJS $http mock respond(...): how to mock a `location` header in the response?

I have an API that responds status 202 with no data, but the response has a header "Location" that points to a URL. I've looked at the $httpBackend respond(...) documentation and see no mention of how to mock a header in the response. I've taken a…
ngDeveloper
  • 1,304
  • 2
  • 16
  • 34
3
votes
0 answers

Angular Unit Testing HTTP

I'm trying to unit test my login function and I'm able to get the function to run but it does not process the $http request. I know this because it logs 'run function' in the console but it does not log 'success' or 'error'. Anyone know the error?…
Peter Graham
  • 2,467
  • 2
  • 24
  • 29
1 2
3
14 15