httpbackend

Unit testing AngularJS with $httpBackend gives “Error: Unexpected Request”

为君一笑 提交于 2019-12-01 16:49:21
问题 I'm gonna preface this question by saying I've already gotten a test to work for my "LoginCtrl" which performs almost the exact same task. I'm sure this is an issue of something really small I've overlooked. Thanks in advance for any help :) I've set the expected value/response for httpBackend for my test, but when I run httpBackend.flush() , it's as if I never set the expectation. Testing code: describe('user register', function () { var scope, RegisterCtrl, httpBackend, userJohnDoe,

Testing backend API via $http in AngularJS/karma/jasmine tests?

依然范特西╮ 提交于 2019-12-01 03:43:55
How do I test my API backend using AngularJS/karma/jasmine tests? I have tried to create the smallest test-case showing my error: echo_server.py from bottle import response, route, run @route('/echo/<echo>') def echo_echo(echo): response.headers['Access-Control-Allow-Origin'] = '*' return {'echo': echo} # Served as JSON if __name__ == '__main__': run() test/unit/apiSpec.js // Should this be in `test/e2e/apiSpec.js`? describe('echo', function () { var scope, http; beforeEach(inject(function ($rootScope, $http) { $http.defaults.useXDomain = true; // CORS scope = $rootScope.$new(); http = $http;

Testing backend API via $http in AngularJS/karma/jasmine tests?

末鹿安然 提交于 2019-12-01 01:00:40
问题 How do I test my API backend using AngularJS/karma/jasmine tests? I have tried to create the smallest test-case showing my error: echo_server.py from bottle import response, route, run @route('/echo/<echo>') def echo_echo(echo): response.headers['Access-Control-Allow-Origin'] = '*' return {'echo': echo} # Served as JSON if __name__ == '__main__': run() test/unit/apiSpec.js // Should this be in `test/e2e/apiSpec.js`? describe('echo', function () { var scope, http; beforeEach(inject(function (

Unexpected request: GET No more request expected at $httpBackend

。_饼干妹妹 提交于 2019-11-28 10:47:47
I have a function in my scope to retrieve the status of my service when the user clicks a button, or when some event are triggered and this function is automatically called. This is my function, defined in the controller I am using: $scope.getStatus = function() { $http({method: 'GET', url: config.entrypoint + config.api + '/outbound/service/' + $scope.serviceId}) .success(function(data) { $scope.errorMessage = ''; $scope.serviceAllGood = data; }) .error(function() { $scope.serviceAllGood = ''; $scope.errorMessage = 'We are experiencing problems retrieving your service status.'; }); } The unit

How do I mock $http in AngularJS service Jasmine test?

依然范特西╮ 提交于 2019-11-28 10:07:27
I am trying to test an AngularJS service carService , but the $httpBackend does not seem to work. //carService angular.module('services').factory('carService', function($http) { return { getTypes: function() { return $http.get('/api/cars/types'); } }; }); Can anybody explain why the response is null? describe("Services", function () { beforeEach(module("app.services")); describe("Car services", function () { var service, $httpBackend; beforeEach(inject(function($injector) { service = $injector.get('carService'); $httpBackend = $injector.get('$httpBackend'); $httpBackend.when('GET', "/api/cars

Unexpected request: GET No more request expected at $httpBackend

一个人想着一个人 提交于 2019-11-27 03:48:40
问题 I have a function in my scope to retrieve the status of my service when the user clicks a button, or when some event are triggered and this function is automatically called. This is my function, defined in the controller I am using: $scope.getStatus = function() { $http({method: 'GET', url: config.entrypoint + config.api + '/outbound/service/' + $scope.serviceId}) .success(function(data) { $scope.errorMessage = ''; $scope.serviceAllGood = data; }) .error(function() { $scope.serviceAllGood = '

How do I mock $http in AngularJS service Jasmine test?

◇◆丶佛笑我妖孽 提交于 2019-11-27 03:26:22
问题 I am trying to test an AngularJS service carService , but the $httpBackend does not seem to work. //carService angular.module('services').factory('carService', function($http) { return { getTypes: function() { return $http.get('/api/cars/types'); } }; }); Can anybody explain why the response is null? describe("Services", function () { beforeEach(module("app.services")); describe("Car services", function () { var service, $httpBackend; beforeEach(inject(function($injector) { service =