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
1
vote
1 answer

Which URL to use when working with $httpBackend expectGET

When expecting a call to the API should I include the entire URL including all the parameters, or do I just need a partial match? Should I be listening for a call to the exact URL : http://address.of.api/stuff/123?include=thing,anotherthing.name; Or…
abyrne85
  • 1,370
  • 16
  • 33
1
vote
1 answer

$httpBackend does not mock $.ajax(...) calls

Trying to create a mock for $.ajax calls using $httpBackend. The below mocking snippet worked fine for worked fine with $http.get('/phones') $httpBackend.whenGET('/phones') But when tried to use the same for $.ajax({ url: '/phones', …
1
vote
0 answers

How do you catch parameters in httpBackend.expectPOST?

AngularJS / Typescript/ AMD / RequireJS / Jasmine / Karma / Sinon I have an AngularJS custom logging service that builds a private internal queue of log messages. This internal queue only counts messages that are not of type debug in its queue. At…
Paul
  • 11
  • 2
1
vote
1 answer

AngularJS testing $httpBackend.whenGET().respond() not working with number as parameter

This test: it("getFooCount success", function () { httpBackend.whenGET('/api/getFooCount').respond(1); fooService.getFooCount(); httpBackend.flush(); expect(fooService.FooCount).toBe(1); }); fails: "Expected null to be…
lwalden
  • 813
  • 7
  • 11
1
vote
1 answer

How do I get $resource to resolve its promise in test environment

I have a controller that needs to run several asynchronous methods that interact with the data on the client and make no calls to the server. I have one method working fine in the browser, but I want to drive the methods with tests and I can't get…
pthalacker
  • 2,056
  • 3
  • 20
  • 37
1
vote
1 answer

AngularJS: Where can I see $httpBackend responses in my browser directly?

My background is not in web development so my terminology might be off, apologies. In short, I have trouble figuring out where $httpBackend is serving data. This question is as much about finding a fix as it is about understanding better how…
matimo2
  • 133
  • 4
1
vote
1 answer

Jasmine error when using $httpBackend

I'm using Jasmine in Visual Studio with chutzpah test adapter on top of AngularJs. I get this error when running the test: Error: Unexpected request: GET /webapi/api/Map Error: Unsatisfied requests: GET /webapi/api/Map/ service: var services =…
Andre
  • 11
  • 3
1
vote
1 answer

Dynamic $httpBackend response in a unit test

I've created a service to mock my backend and allow paging of content: angular.module('testedApp') .service('mockedResponses', function mockedResponses() { var _mediaResponse = {"total":84,"media":[...], groups: {}, keywords: {}}; …
Oleg Belousov
  • 9,981
  • 14
  • 72
  • 127
1
vote
2 answers

Angularjs $httpBackend unexpected request

I am trying to set up a unit test for AngularJS controller which includes a service that calls $http.get method. However, even though I use $httpBackend.expectGET before $httpBackend.flush(), app is trying to GET template HTML resources, so it…
Özüm
  • 55
  • 1
  • 3
1
vote
1 answer

AngularJS - Using ngMockE2E $httpBackend how can I delay a specific response?

I'd like to delay the response to the following whenGET: $httpBackend.whenGET(/^foobar/).respond(function () { return [200,{}]; }); However it seems impossible using $timeout to do this synchronously, so I'm not sure how to approach this?
Keir
  • 440
  • 6
  • 15
1
vote
1 answer

how to not duplicate httpBackend code in angular tests?

I have some services that call for data while loading. so my tests fail because there are unexpected calls that I need to specify in $httpBackend. this causes a lot of duplicate code in my tests. part of my attempts to reduce the duplicated code,…
guy mograbi
  • 27,391
  • 16
  • 83
  • 122
1
vote
2 answers

Testing with $httpBackend and angular-translate directive

I am expending a lot of time trying to understand how the $httpBackend and the angular-translate could work together in order to test if the translation functionality still works. I am in this point, and I really don't know how to solve this…
DanielM
  • 1,106
  • 3
  • 17
  • 27
1
vote
1 answer

unit testing : http call in controller inside directive

describe("File Upload directive", function() { var elm, scope,httpBackend , controller , isolateScope; beforeEach(angular.mock.module("fileApp")); beforeEach(angular.mock.inject(function($rootScope, $compile , $httpBackend) { …
vijay
  • 2,034
  • 3
  • 19
  • 38
1
vote
1 answer

whenDELETE : undefined is not a function

Here is what I am doing : controller.js var app = angular.module('app', [ 'angularFileUpload' ]); app.controller('MyCtrl', [ '$scope', '$http', '$timeout', '$upload', function($scope, $http, $timeout, $upload) { $scope.something; …
vijay
  • 2,034
  • 3
  • 19
  • 38
1
vote
2 answers

unit testing a recursive http request with angular httpbackend

I am doing unit testing on my AngularJS app using their setup with jasmine and karma. I have been using AngularJS mock $httpbackend: https://docs.angularjs.org/api/ngMock/service/$httpBackend The problem I have is testing the following…