Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 268dbd4

Browse files
committed
fix(ngMock): pass failed HTTP expectations to $errorHandler
This was only partially fixed in f18dd29
1 parent e500fb6 commit 268dbd4

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/ngMock/angular-mocks.js

+15-5
Original file line numberDiff line numberDiff line change
@@ -1511,15 +1511,25 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
15111511
}
15121512

15131513
if (expectation && expectation.match(method, url)) {
1514+
var expectationError;
1515+
15141516
if (!expectation.matchData(data)) {
1515-
throw new Error('Expected ' + expectation + ' with different data\n' +
1516-
'EXPECTED: ' + prettyPrint(expectation.data) + '\nGOT: ' + data);
1517+
expectationError = new Error('Expected ' + expectation + ' with different data\n' +
1518+
'EXPECTED: ' + prettyPrint(expectation.data) + '\n' +
1519+
'GOT: ' + data);
15171520
}
15181521

15191522
if (!expectation.matchHeaders(headers)) {
1520-
throw new Error('Expected ' + expectation + ' with different headers\n' +
1521-
'EXPECTED: ' + prettyPrint(expectation.headers) + '\nGOT: ' +
1522-
prettyPrint(headers));
1523+
expectationError = new Error('Expected ' + expectation + ' with different headers\n' +
1524+
'EXPECTED: ' + prettyPrint(expectation.headers) + '\n' +
1525+
'GOT: ' + prettyPrint(headers));
1526+
}
1527+
1528+
if (expectationError) {
1529+
// In addition to be being converted to a rejection, this error also needs to be passed to
1530+
// the $exceptionHandler and be rethrown (so that the test fails).
1531+
expectationError.$$passToExceptionHandler = true;
1532+
throw expectationError;
15231533
}
15241534

15251535
expectations.shift();

0 commit comments

Comments
 (0)