diff --git a/src/ng/q.js b/src/ng/q.js index c2fb12361..22c390b05 100644 --- a/src/ng/q.js +++ b/src/ng/q.js @@ -364,6 +364,10 @@ function qFactory(nextTick, exceptionHandler, errorOnUnhandledRejections) { } } catch (e) { rejectPromise(promise, e); + // This error is explicitly marked for being passed to the $exceptionHandler + if (e && e.$$passToExceptionHandler === true) { + exceptionHandler(e); + } } } } finally { diff --git a/src/ngMock/angular-mocks.js b/src/ngMock/angular-mocks.js index 3416448b4..55ffe2c97 100644 --- a/src/ngMock/angular-mocks.js +++ b/src/ngMock/angular-mocks.js @@ -1438,10 +1438,16 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) { return; } } - throw wasExpected ? + var error = wasExpected ? new Error('No response defined !') : new Error('Unexpected request: ' + method + ' ' + url + '\n' + (expectation ? 'Expected ' + expectation : 'No more request expected')); + + // In addition to be being converted to a rejection, this error also needs to be passed to + // the $exceptionHandler and be rethrown (so that the test fails). + error.$$passToExceptionHandler = true; + + throw error; } /** diff --git a/test/ngMock/angular-mocksSpec.js b/test/ngMock/angular-mocksSpec.js index e596bcb44..55703c7f4 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};