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

how to properly write url in httpBackend service in unit tests

I want to mock $httpBackend.whenGet request. I can write full url as string, but i can not uderstend with last part where i define queryExpression: "('120' != 1 AND '106' != 5)" Example of request from console that working:…
rossoneri
  • 443
  • 5
  • 17
0
votes
1 answer

can $httpbackend be called with different url

I have a service that calls a REST URL that returns data. My sample code would be $http('POST', '/mockUrl/resource/'+resourceValue).then(...); My service works fine and it returns data. My problem is how do I test this in karma. Right now I have…
manu
  • 77
  • 1
  • 3
  • 14
0
votes
1 answer

Accessing $httpBackend in Jasmine it block

Please see my code example below, I have a protractor test that get's run as a GULP task by angular-protractor. I want to be able to mock some REST calls for all it blocks, but also have access to the httpBackend for specific it blocks. I'm having…
Anton Rand
  • 322
  • 5
  • 20
0
votes
1 answer

unexpected GET request on karma unit testing

I am using karma to test a controller in my angular app, the app it self works as expected but unit test throws error: unexpected request: GET views/home.html as I got the problem is by ui-router and $httpBackend. so one approach was caching by…
Amir-Mousavi
  • 4,273
  • 12
  • 70
  • 123
0
votes
1 answer

AngularJS mocking responses with $httpBackend

The following HTTP request, intercepted by the ngMockE2E module "$httpBackend, never completes. What is the proper way to get a response from $httpBackend? var app = angular.module('app', ['ngMockE2E']); app.controller('Foo',…
Xeoncross
  • 55,620
  • 80
  • 262
  • 364
0
votes
0 answers

angularjs - e2e mocked backend

I'm trying to mock the backend so that I can write some e2e tests. I searched online but I can't figure out what i'm doing wrong. I get this error on the first line of my code: angular is not defined. My protractor config file is: exports.config =…
Nick
  • 13,493
  • 8
  • 51
  • 98
0
votes
0 answers

$httpBackend doesn't seem to be flushing requests

I am testing my Angular app using ngDescribe. I don't think ngDescribe should be too much of a problem here, as it's just managing dependency injection for me. I first began to attempt my test the way the ngDescribe docs say, in the code below I…
Justin
  • 2,265
  • 4
  • 15
  • 21
0
votes
1 answer

Testing angular $http inside promise chain with mocha

I have jsdom/mocha/chai set up for backend angular testing. I have a service that essentially does this (intentionally no post data): app.service('testService', ['config', '$http', function(config, $http) { function getSpecificConfig(type) { …
Dreamlines
  • 380
  • 4
  • 15
0
votes
1 answer

How to get unit test working with $httpBackend?

I am just starting getting my head around unit testing and angular 1.2. I am using the $httpBackend service for testing a $httpcall in a service. This service is called inside my controller: var app = angular.module('myApp',…
bier hier
  • 20,970
  • 42
  • 97
  • 166
0
votes
1 answer

Protractor http-backend-proxy 401 Unauthorized error

I am using protractor and mocking the backend calls using http-backend-proxy. I login and it makes a call which I have mocked. I then clear the token in the local storage using browser.executeScript( 'localStorage.clear();' ); And then I perform…
reutsey
  • 1,743
  • 1
  • 17
  • 36
0
votes
2 answers

how is angular mock's httpBackend passed implicitly to the $controller service in tests?

This spec passes, even though it looks like it should fail. (the code is from a book on angular and rails) here is the angular app: var app = angular.module('customers',[]); app.controller("CustomerSearchController", ["$scope", "$http",…
Leo D
  • 209
  • 2
  • 5
0
votes
3 answers

How to create dynamic regex in javascript

I want to use $htppBackend to mock some service. My problem is some of service url have parameter, ex: http://domain/service1?param1=a¶m2=b I need an regex which can reconize http://domain/service1 is correct for…
Stiger
  • 1,189
  • 2
  • 14
  • 29
0
votes
0 answers

angularjs - $httpbackend error: Unexpected request

I know that there are plenty of questions like this, but none of those worked for me and I don't really know what's going on and why they don't work on my specific case. I'm trying to test a controller using $httpBackend. Unfortunately, I always…
Nick
  • 13,493
  • 8
  • 51
  • 98
0
votes
1 answer

httpBackend.expectPUT not working in angularjs factory unit test

Below is the sample service that I'm trying to unit test: angular.module('sampleModule') .factory('sampleService', sampleService); sampleService.$inject = ['$http']; function sampleService($http) { var endpoint =…
Pramodh
  • 186
  • 2
  • 13
0
votes
1 answer

$httpBackend e2e not respoding with data

I have a mock server that respond with some data backendMock.run(function($httpBackend){ $httpBackend.whenGET('views/login.html').passThrough(); $httpBackend.whenGET('views/home.html').passThrough(); …
Shubham
  • 189
  • 9