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

Unable to use httpBackend flush for ngMockE2E

I am trying to test my controller using jasmine. Basically, when the controller is created it will call a service to make http request. I am using httpBackend to get the fake data. When I try to run the test I always get the error "No pending…
Steven
  • 415
  • 1
  • 4
  • 12
1
vote
1 answer

Angular - Testing http services with httpBackend throws unexpected exception

The module definition var module = angular.module('test', []); module.provider('client', function() { this.$get = function($http) { return { foo: function() { return $http.get('foo'); } } …
brazorf
  • 1,943
  • 2
  • 32
  • 52
1
vote
1 answer

Cant pass my test with my post http function with jasmine

I can't understand why my post function doesn't pass my jasmine test. I think that issues with $httpBackend is very poor in AngularJS documentation This is my code: .controller('SystemControllerNg', ['sweetAlertService', 'dataExchangeService',…
1
vote
1 answer

$httpBackend.flush() needs to call on each test : Jasmin-AngularJs Unit Test

My question is very simple unlike afterEach (function () { $httpBackend.verifyNoOutstandingExpectation (); $httpBackend.verifyNoOutstandingRequest (); }); why $httpBackend.flush() cant be placed inside afterEach(function(){}…
shreyansh
  • 1,637
  • 4
  • 26
  • 46
1
vote
0 answers

Print PDF file with the default printer

I'm developing a backend application using C# and I need to do a very simple thing: to print an existing PDF file using the default printer when the application receives some HTTP request. I don't need any "printer choose" window or anything else,…
Salivan
  • 1,876
  • 7
  • 26
  • 45
1
vote
0 answers

$httpbackend delay with $q and $resource

I'm trying to make a delay inside of $httpBackend response, and handle it with $resource service like this: $httpBackend.whenGET(/\/courses\/\?id=\d+$/).respond(function(method, url) { var regexp = /\d+$/; var position = url.search(regexp); …
Vladimir Mironov
  • 655
  • 1
  • 7
  • 23
1
vote
0 answers

'No more request expected' error when using $httpBackend

I'm trying to test a simple call to my API, and I'm going round in circles trying to work out why it's failing. I've simplified things a bit. This would be the error for the test below: Error: Unexpected request: GET /api/search?blah=something No…
J_P
  • 599
  • 1
  • 9
  • 20
1
vote
1 answer

Testing $httpBackend in Jasmine + Angular

I think I do everything the same way as in tutorials and there is weird bug. I want to mock $http in my LoginService and test it. Unfortunately there are some problems - it looks like it doesn't see $httpBackend functions. This is my…
Mossar
  • 425
  • 1
  • 5
  • 14
1
vote
1 answer

Angular uiRouter Resolve exception

Why do get I following error got Angular uiRoute while working with $httpBackend This is my mock services that gets hit: $httpBackend.whenGET(editingRegex).respond(function (method, url) { var parameters = url.split('/'); var…
eugenekgn
  • 1,652
  • 2
  • 17
  • 38
1
vote
0 answers

Testing chained Promises with AngularJS $http in karma

I'm trying to return a Promise in a Promise after a $http call, but it never gets resolved in the karma/jasmine test case. Here's the code: $httpBackend.expectGET('/dummy').respond('foo'); var p = $http.get('/dummy').then(function(response) {return…
jonnie
  • 101
  • 1
  • 10
1
vote
1 answer

Where should $httpBackend.expect() go?

The following test passes: admin.controller.js angular .module('mean-starter') .controller('AdminController', AdminController); function AdminController(User, Auth, $state) { var vm = this; User .list() .success(function(data) { …
Adam Zerner
  • 17,797
  • 15
  • 90
  • 156
1
vote
1 answer

Karma: trouble modularizing testing of requests

Here is the controller I'm testing: angular .module('mean-starter') .controller('AdminController', AdminController); function AdminController(User, Auth, $state) { var vm = this; User .list() .success(function(data) { vm.users…
Adam Zerner
  • 17,797
  • 15
  • 90
  • 156
1
vote
1 answer

Error when testing PUT/POST methods of $resource using $httpBackend

I am having an issue where I am trying to test a service that has been set up using $resource, and has various methods GET, PUT, POST. I am using $httpBackend in my tests, and it works fine when testing the GET requests but fails on the PUT/POST - I…
1
vote
0 answers

$httpBackend.expectGET fails if controller makes request on page load

I've just killed hours of my live trying to solve this. In a controller I call a method making an HTTP request on page load: $scope.getPosts = function() { /* call to service */ }; /// Call it immediately $scope.getPosts(); I expect this in my unit…
1
vote
0 answers

AngularJS + Jasmine Unit Testing - $httpBackend's respond not updating scope values

I am currently trying to learn how to unit test angular code, and I am using Jasmine to do so. I have the following AngularJS specific code: /// angular.module('testModule',…