fix(ngMock): pass unexpected request failures in $httpBackend to the error handler
Closes #16150 Closes #15855
This commit is contained in:
committed by
Peter Bacon Darwin
parent
97b00ca497
commit
f18dd2957c
@@ -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 {
|
||||
|
||||
Vendored
+7
-1
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Vendored
+20
-1
@@ -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};
|
||||
|
||||
Reference in New Issue
Block a user