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

Activate $httpMock after angular app has been initialized

I want to be able to turn on and off a $httpBackend mock in my angularJS app. That means I want to inject the $httpBackend lazily/on demand. It would also be nice to be able to turn it on and off again. For example to provide input data for an…
David Karlsson
  • 9,396
  • 9
  • 58
  • 103
1
vote
0 answers

Angular unit testing with ngMock - $timeout.flush() throws exception

I am using ngMock for unit testing and I need to use the $timeout.flush function in one of my tests, so I have added the two following lines to my test: $timeout.flush(); $timeout.verifyNoPendingTasks(); as indicated on…
1
vote
1 answer

mocked backend GET request not caught by service method

I'm building a test for a controller name GeneController that uses a service called Gene to make a bunch of API GET requests. I've mocked the main GET request like this and I'm pretty sure it's working properly: $httpBackend.expectGET…
1
vote
1 answer

unable to mock $httpbackend whenPOST for Jasmine-karma

I am using angular js and I have a controller.js for which I want to write jasmine test case. I am able to call the function of controller in my testcase. There is a local function in my controller which is called by method in scope (for which I am…
user4582986
1
vote
1 answer

When I use $httpBackend.expectGET() or $httpBackend.expectDELETE(), webstorm tells me: Unresolved function or method, for some reason

I'm using jasmine framework on karma test running platform. I'm completely new to testing API's. So, according to my initial plan, I need to test $response with $httpBackend. Whenever I run test, it fails. And Webstorm highlights for some reason…
1
vote
0 answers

test login with karma failed, got error of unexpected request

I got error of using karma testing my auth endpoint Error: Unexpected request: GET partials/dashboard.html No more request expected My spec.js describe('LogController', function() { var $scope, controller, $location, $window; …
Jenny Mok
  • 2,744
  • 9
  • 27
  • 58
1
vote
2 answers

jasmine error $httpBackend Unexpected request without domain

My jasmine test for $httpBackend won't work unless I add the domain name, i.e. http://localhost:9808/ Since this test is used in several different environments I cannot use http://localhost:9808/ Without the domain I get this error: Uncaught…
GamerDev
  • 2,006
  • 4
  • 24
  • 31
1
vote
1 answer

Alternative for http-backend-mock and ngE2e for a react application

Currently, I have been using ngMockE2e and httpbackend mock with protractor for an angular page. Now we are thinking of using react for development, Is there any alternative which I can use for mocking stuff for end to end testing for http calls.
Dinesh
  • 149
  • 1
  • 3
  • 12
1
vote
3 answers

Android-How do i get image urls stored on a server then load the images using picasso

Issues Faced I was able to get image url data using Okhttp but then store it on an arraylist but was faced with an issue because this processes takes time so when my activity start the view is seen before the data is received. I am querying image…
1
vote
1 answer

Mocking $httpBackend on controller initialisation with unknown json data

When mocking using $httpBackend, How do I create the mock when I do not know exactly the type of data being returned. I want the http call to be on controller initialsation. One caveat is that it will be a json object being returned. (function ()…
1
vote
2 answers

$httpBackend being ignored, Jasmine calling actual endpoint

I'm writing a test to simply check that an endpoint is being called by a service. I'm using $httpBackend to mock this response, however the test is still hitting the real backend endpoint, and not using the $httpBackend mock. Service function…
js2015
  • 45
  • 5
1
vote
3 answers

Why is my jasmine test failing for my Angular app

I have the following code ... and one of the tests is failing. Please help me in understanding why, and suggest me a way to rectify.
Amarsh
  • 11,214
  • 18
  • 53
  • 78
1
vote
1 answer

AngularJS unexpected request ngmock

I get an unexpected request error on GET /#/car/view/0 where 0 is the :carId. It's for a basic angular crud application on a ngMock backend. The $httpBackend.whenGET(carUrl) works and gives back a list of all cars. The addCar() also works. I can't…
1
vote
2 answers

Problems testing $http.get when returning json data with Jasmine and AngularJs

I've struggling the whole day already figuring out how to test the result of a $http.GET request which is returning data from a .json file. I hope any of you can be of any help here.. Practical the app is running perfectly and is returning the…
Lars Meijdam
  • 1,177
  • 1
  • 10
  • 18
1
vote
0 answers

Angular testing of a failing promise

I am trying to test a failing promise service 'resolveService' function: return {resolveRedirect: function(){ var deferred = $q.defer(); $http.jsonp('randomUrl') .then(function(response){ …
Dribel
  • 465
  • 1
  • 10
  • 24