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

$httpbackend.flush() throws current.$$route.title is undefined

I try to unit test a simple factory that make a post request : 'use strict'; angular.module('app').factory('UserFactory', function ($http, $rootScope, $location) { return { 'addUser': function (user) { $http.post('/api/user', …
Getz
  • 3,983
  • 6
  • 35
  • 52
0
votes
2 answers

How to check headers in any request in angular?

I've been trying to test the process when any request was sended and I want check if the headers are ok. What have I done wrong? check this codepen: http://codepen.io/gpincheiraa/pen/qZPrEp App.js angular .module('exampleApp') …
0
votes
1 answer

angular $httpBackend.when mocks - delay response NOT globally

I found this article how to create an artificial server delay when using $httpBackend for mocking data. Is there any way at all to have this on a per-mock basis? Perhaps something like: $httpBackend .whenGET(/\/my\/endpoint$/) …
parliament
  • 21,544
  • 38
  • 148
  • 238
0
votes
1 answer

Match mock-$httpBackend data from $resource service in jasmine unit test

Simply Put: Can I match mock-$httpBackend data from $resource service in a jasmine unit test? How would I do it? What I Want: When I Jasmine-test my backend services with $httpBackend and the $http service, I can do this: it("should return movie…
0
votes
0 answers

$httpBacked, Error: Unsatisfied requests for regexed when statement

var baseUrl = 'http://localhost:3481'; before each test I adding handler for that GET request $httpBackend.when('GET', new RegExp(baseUrl + '/reports\\?.*', 'g')) in one of it expression, I'm expecting the following request var startTime =…
BotanMan
  • 1,357
  • 12
  • 25
0
votes
1 answer

"Unsatisfied requests" when testing angularJS with Jasmine

I'm trying to write which tests if user uses right login/pass: describe('LoginController', function () { beforeEach(angular.mock.module('task6')); var $rootScope, $controller, LoginService, $httpBackend, …
Vladimir Mironov
  • 655
  • 1
  • 7
  • 23
0
votes
1 answer

Testing AngularJS with Jasmine / Karma with $httpBackend not working

I'm trying to unit test my app built on Angular with Jasmine via Karma. The app involves making a call to the GitHub API and pulling the names of all the repos of a user and filling an array with those names. I'm trying to test that the array is…
0
votes
1 answer

how can I mock a response status using httpBackend in angulatJS depending on the posted data?

I'm using angular-mock to simulate an httpBackend for an Angular app. The response status should depend on the posted data. I'm not using this for testing, but as a full frontend version of a fullstack (PHP-Angular) application. Is this even…
0
votes
1 answer

With $httpBackend .then promise works but .success callback doesn't

I have the following backend definition in my test file: authRequestHandler = $httpBackend.whenPOST(my_request_url) .respond( { userId: 'panda', token: 'panda_token' }); And in my controller I tried both…
mila
  • 471
  • 8
  • 20
0
votes
1 answer

Calling a method from an injected service in Jasmine

I'm attempted to unit test a service. I've injected the service however the method call getAllProducts() doesn't appear to run however the test still passes! Plnkr service.js angular.module('vsApp') .factory('productsDataService', function($http)…
benc
  • 1,978
  • 3
  • 15
  • 22
0
votes
1 answer

karma mock promise response

I have the following factory that I'd like to test: angular .module('enigma.authFactory', []) .factory('authFactory', authFactory); authFactory.$inject = ['$http']; function authFactory($http){ function doesUserExist(email){ …
efarley
  • 8,371
  • 12
  • 42
  • 65
0
votes
1 answer

How to get regex value from $httpBackend whenGET

$httpBackend.whenGET(/api\/product\/[a-zA-Z0-9]{6}/).respond(function(data) { // Code to find given ID in collection }); When I call this endpoint, I should return the product that matches the given product ID (the regex value). How do I…
Paul Erdos
  • 1,355
  • 2
  • 23
  • 47
0
votes
2 answers

$httpBackend jsonp: No pending requests to flush

On a button click, I make a jsonp call. function clickHandler(e) { e.preventDefault(); var url = "some.url.with?params"; $http.jsonp(url).success(function () {$scope.success();}) …
Empty
  • 350
  • 2
  • 4
  • 22
0
votes
1 answer

httpBackend explicit annotation for Angular app in strict mode

I am using Protractor's addMockModule functionality to mock some request data, but am having issues with the target Angular app being in strict mode. This is the error: Failed: unknown error: [$injector:strictdi] function($httpBackend) is not using…
magicode118
  • 1,444
  • 2
  • 17
  • 26
0
votes
2 answers

Which SQL Query is the site running?

The websites (intranet sites or extranet sites - sometimes web portals) at my company return certain results (which is obtained via SQL queries/commands in the back-end systems). I"m trying to find out which queries are being run in the background…
LearnByReading
  • 1,813
  • 4
  • 21
  • 43