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

Testing Angular-Resource: Expected an Object, got a Resource

When trying to test some simple angular code using $resource, I end up with a Resource object which contains a $promise key and hence a failure of the form: Failure/Error: Expected Resource(...) to equal Object(...) I was expecting to get back the…
sunless
  • 597
  • 5
  • 19
2
votes
2 answers

AngularJS Unit tests broken after $httpBackend decorator

So I had a situation where we had to hit a "restful" service not under our control, where in order to get json back from the service on a GET call, we have to pass Content-Type="application/json" in the header. Only problem is that Angular strips…
Shaggy13spe
  • 733
  • 10
  • 22
2
votes
2 answers

$httpBackend expectGET not returning expected data

I will just start out saying that $httpBackend and spyOn are pretty new to me, and I am struggling to get a clear picture of what is happening. Basically, I'm trying to do an $httpBackend.expectGET('/myroute/').respond(...) and then use spyOn, but…
westandy
  • 1,360
  • 2
  • 16
  • 41
2
votes
1 answer

AngularJS - $httpBackend cannot read nested JSON property

I am trying to set up a http GET request expectation via jasmine but I'm getting following error: TypeError: Cannot read property 'user' of undefined The service function I want to test looks like: function getData() { return…
The_Dude
  • 397
  • 1
  • 3
  • 16
2
votes
0 answers

Can I call functions in a module added with addMockModule? (protractor)

I am currently using Protractor to test an AngularJS app, mocking its backend with browser.addMockModule() (based on the discussion on #125) and using the $httpBackend mock for E2E testing with an additional "data" module (myDataModule) that helps…
germanio
  • 861
  • 1
  • 17
  • 27
2
votes
0 answers

Dynamical URL in $httpbackend - Angular unit testing

I am trying to dynamically add URL parameter to $httpbackend.whenGET urlAll = "http://localhost:8080/api/Log"; urlById = "http://localhost:8080/api/Log?id="; $httpBackend.whenGET(urlAll).respond(...); - This is Working…
Vis
  • 21
  • 3
2
votes
1 answer

AngularJS Jasmine Test - how to skip over a request

We have a set of test cases which is common for many different forms. Some of the forms may trigger a lazy loader which would prefetch some data in their post section of the directive, so firing a HTTP GET. In the common test's beforeEach, I thus…
Petr Osipov
  • 621
  • 6
  • 16
2
votes
1 answer

Catching params using $httpBackend

Trying to get a Param from this url: /api/events/{id} $httpBackend.whenGET(/\/api\/events\/(.+)/, undefined, undefined, ['eventID']) .respond(function(method, url, data, headers, params) { console.log('get-params:…
WayneJohn
  • 53
  • 6
2
votes
0 answers

Karma test with $httpBackend - No pending requests to flush

Preface: I have 2 methods called injections and controllerInjections which simply simplify injecting into the test. It puts the injections inside this. My test looks like this: describe "user profile controller", -> beforeEach module(APP_NAME) …
casraf
  • 21,085
  • 9
  • 56
  • 91
2
votes
1 answer

Why $httpBackend doesn't populate params

I have a $resource which I use to handle entity's crud http requests. It's wrapped in my custom service which at the moment doesn't add any functionality, so never mind it - it's just old plain $resource: app.factory('coursesService', ['$resource',…
2
votes
0 answers

Evaluating $httpBackend.expectGet('url') results in 'undefined' is not a function error

I'm trying to write a unit test for a service using $httpBackend to mock http requests. For now I'm just trying to get expectGET to work but I get the following error: TypeError: 'undefined' is not a function (evaluating…
photon
  • 606
  • 4
  • 14
  • 31
2
votes
2 answers

How do I test my HTTP call when I use a config to build the URL?

In my project I build some of my HTTP requests like so: var options = { params:{ foo: 'bar' hello: world } }; $http.get("my/service", options) Which means that the final HTTP call looks something like…
David says Reinstate Monica
  • 19,209
  • 22
  • 79
  • 122
2
votes
1 answer

Unit test $httpBackend with query params

Using $httpBackend, how can I use expectGET with a url that has query params? The order doesn't matter, and the value doesn't matter. $httpBackend .expectGET('/api/my_endpoint/example?X=false&Y=someethingelse&Z=anotherthing') .respond(200,…
cusejuice
  • 10,285
  • 26
  • 90
  • 145
2
votes
2 answers

Pass params to $httpBackend

I'm trying to mock a $http get request with parameters. Using the actual $http service we could do something like this $http.get(url, {params : { articleId:10, id : 1}}) .success(function (response) { …
Obi
  • 3,091
  • 4
  • 34
  • 56
2
votes
0 answers

How to send cookies from angular mock backend?

I am currently involved in backendless development of app front-end using angular's $httpBackend service in ngMock module. I am able to send responses for request using mock backend, but I haven't been able to find a method to send cookies using…
Abdul23
  • 5,265
  • 2
  • 16
  • 23