From c1ad9acf953cca48a8a4d40a39628035e41a8096 Mon Sep 17 00:00:00 2001 From: Marcin Wosinek Date: Sun, 6 Aug 2017 11:38:52 +0100 Subject: [PATCH] test($httpBackend): check if unexpected request fail on verify no outstanding request --- test/ngMock/angular-mocksSpec.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/test/ngMock/angular-mocksSpec.js b/test/ngMock/angular-mocksSpec.js index e596bcb44445..55703c7f4599 100644 --- a/test/ngMock/angular-mocksSpec.js +++ b/test/ngMock/angular-mocksSpec.js @@ -2429,7 +2429,7 @@ describe('ngMock', function() { describe('ngMockE2E', function() { describe('$httpBackend', function() { - var hb, realHttpBackend, realHttpBackendBrowser, callback; + var hb, realHttpBackend, realHttpBackendBrowser, $http, callback; beforeEach(function() { callback = jasmine.createSpy('callback'); @@ -2442,10 +2442,29 @@ describe('ngMockE2E', function() { module('ngMockE2E'); inject(function($injector) { hb = $injector.get('$httpBackend'); + $http = $injector.get('$http'); }); }); + it('should throw error when unexpected request - without error callback', function() { + expect(function() { + $http.get('/some').then(noop); + + hb.verifyNoOutstandingRequest(); + }).toThrowError('Unexpected request: GET /some\nNo more request expected'); + }); + + + it('should throw error when unexpected request - with error callback', function() { + expect(function() { + $http.get('/some').then(noop, noop); + + hb.verifyNoOutstandingRequest(); + }).toThrowError('Unexpected request: GET /some\nNo more request expected'); + }); + + describe('passThrough()', function() { it('should delegate requests to the real backend when passThrough is invoked', function() { var eventHandlers = {progress: angular.noop};