Note that there are some explanatory texts on larger screens.

plurals
  1. POAngularJS Issues mocking httpGET request
    primarykey
    data
    text
    <p>so I'm new to angularjs and its mocking library. I am trying to test that a specific GET request is made, but I always get this error for the 2nd assertion and can't figure out why:</p> <pre><code>Error: Unsatisfied requests: GET /1.json </code></pre> <p>Is there anything I messed up with my code below?</p> <p>App.js</p> <pre><code>var App = angular.module('App', []).config(['$routeProvider', function($routeProvider) { $routeProvider.when('/', { templateUrl: 'views/main.html', controller: 'MainCtrl' }).when('/Items', { templateUrl: 'views/items.html', controller: 'Ctrl' }).otherwise({ redirectTo: '/' }); }]); </code></pre> <p>Ctrl.js</p> <pre><code>function Ctrl($scope, $http, $filter) { $scope.items = []; $http.get('/1.json').success(function(data) {$scope.items = data.items;}); } Ctrl.$inject = ["$scope","$http", "$filter"]; </code></pre> <p>Spec/Ctrl.js</p> <pre><code>describe('Controller: Ctrl', function() { var $httpBackend; // load the controller's module beforeEach(module('App')); beforeEach(inject(function($injector) { $httpBackend = $injector.get('$httpBackend'); // backend definition common for all tests $httpBackend.whenGET('/1.json').respond('Response!'); })); afterEach(function() { $httpBackend.verifyNoOutstandingExpectation(); $httpBackend.verifyNoOutstandingRequest(); }); var Ctrl, scope; // Initialize the controller and a mock scope beforeEach(inject(function($rootScope, $controller) { scope = $rootScope.$new(); Ctrl = $controller('Ctrl', { $scope: scope }); })); it('should initialize with 0 items', function() { expect(scope.items.length).toBe(0); $httpBackend.flush(); }); it('should make store request', function(){ var controller = scope.$new(Ctrl); $httpBackend.expectGET('/1.json'); $httpBackend.flush(); }); }); </code></pre> <p><strong>EDIT</strong>: added app and controller code.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload