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 return promise value issue

I want to implement a login function using AngularJS and my backend is in Rails. i decided to implement it using the $httpBackend but I have a problem. When it gets into the $httpBackend function, it does update the token with the latest token from…
Kingsley Simon
  • 2,090
  • 5
  • 38
  • 84
0
votes
1 answer

AngularJs controller test: unexpected request : GET

I am trying to write my first test for controller by mocking the service layer using karma-jasmine and httpBackend. But I am getting this error. Error: Unexpected request: GET./webresources/campaign/getCampaignDetails/undefined Expected GET…
user1061117
  • 51
  • 1
  • 1
  • 3
0
votes
1 answer

Error: No more request expected with Karma using Restangular from within a Service

I have an AngularJS service and service name is User. I use it for authentication. Inside this service, I have an authenticate() function which uses Restangular to make a REST call to our API. It's perfectly working in my Angular application. I just…
devwannabe
  • 3,160
  • 8
  • 42
  • 79
0
votes
1 answer

angular unit testing advice

I'm new to unit testing with Angular and I'm having a great deal of trouble even getting starting with the testing. I have a controller that calls a service that calls a remote api to get a list of currencies, and then augments the returned object…
Mike Alizade
  • 55
  • 1
  • 1
  • 7
0
votes
1 answer

Get http result after httpBackend flush

I have a test case that tests a service and have succeeded in checking if a get request is called in my test case : var $httpBackend, Entry, Common; beforeEach(module('contact_journal')); beforeEach(inject(function($injector,…
Ashish Gaur
  • 2,030
  • 2
  • 18
  • 32
0
votes
1 answer

Angular Jasmine $httpBackend Response Tests

I'm trying to test the response of an http call. The problem is, it passes no matter what response code I put in there or response data. Any ideas? Thanks! Controller.js $scope.getPresses = function() { var pressRequest = { method:…
Peter Graham
  • 2,467
  • 2
  • 24
  • 29
0
votes
1 answer

Jasmine make real data rest calls

Jasmine could use $httpBackend to make fake restful calls by using $httpBackend.whenGet("https://www.test.com") .respond({....}) But can I make real data calls to the server I make?
Gabriel
  • 601
  • 1
  • 10
  • 26
0
votes
0 answers

AngularJS - $httpBackend return 200 with success = false

I've bumped into some very strange behaviour when trying to mock server-api while performing e2e tests. Here's my code: $httpBackend.whenPOST(...).respond(function () { return [200, {success:true, errors: []}]; }); This part works fine,…
Gil Moshayof
  • 16,633
  • 4
  • 47
  • 58
0
votes
0 answers

Unit testing AngularJS controller , Accessing Json in spec file

How do i access a json object in the controller spec ? tried a lot of options of the net with jasmine getJson Fixtures and httpbackend but nothing seems to work. beforeEach(inject(function ($injector,$controller, $rootScope, $q,…
user1779385
  • 41
  • 1
  • 5
0
votes
0 answers

httpBackend.flush() results in error callback called instead of success callback

I've got a perfectly working service (a provider, really) that calls a $resource in its $get. Trying to unit test it, I use httpBackend to mockthe response. I inject the service into my test. The resource gets called. I flush() httpBackend, but…
mcv
  • 4,217
  • 6
  • 34
  • 40
0
votes
2 answers

An issue with testing $resource service by $httpBackend

I guess I miss something. Have spent some time trying to understand why my test is not working. The code. angular.module('services') .factory('UserPreferencesService', ['$resource', function ($resource) { return…
ses
  • 13,174
  • 31
  • 123
  • 226
0
votes
1 answer

TypeError: Cannot read property '_scope' of undefined

I get that error when I run my test in Jasmine. I'm trying to create a test for a mock ajax call. The data itself is not important, I'd just like to see the test run. My code: export interface IMockScope extends ng.IScope { …
0
votes
1 answer

Testing a basic Angular Service

Ok so this is my setup: var app = angular.module("KamajiDash", ['ngResource','ui.bootstrap'.. 'elasticsearch']); app.service("elbService",function($http) { this.remove_instance = function(elb_id, instance_id) { …
Rebekah Waterbury
  • 22,236
  • 5
  • 23
  • 28
0
votes
1 answer

$urlRouterProvider creates $httpBackend errors

I'm using the $httpBackend service to mock requests for my Service tests. However, I began getting errors in my tests that suggested the requests were actually being made vs being mocked. When I commented out the catch all route I provided in my app…
evkline
  • 1,451
  • 3
  • 16
  • 34
0
votes
1 answer

Why does $httpBackend not respond?

I'm having difficulty learning to unit test some AngularJS code using Karma and am getting hung up on the use of $httpBackend. I've created a distilled version of the test, showing only where I mock the get request and expect to see a non-failing…
phatfingers
  • 9,770
  • 3
  • 30
  • 44
1 2 3
14
15