-
Notifications
You must be signed in to change notification settings - Fork 27.5k
fix(ngMock): pass failed HTTP expectations to $errorHandler #16644
Conversation
268dbd4
to
d548e10
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - now we just need to convince Travis.
@petebacondarwin It won't be easy. See https://stackoverflow.com/questions/46913856/value-is-not-a-sequence-safari-exception window.console.error('AngularJS: disabling automatic bootstrap. <script> protocol indicates ' +
'an extension, document.location.href does not match.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'EXPECTED: ' + prettyPrint(expectation.data) + '\nGOT: ' + data); | ||
expectationError = new Error('Expected ' + expectation + ' with different data\n' + | ||
'EXPECTED: ' + prettyPrint(expectation.data) + '\n' + | ||
'GOT: ' + data); | ||
} | ||
|
||
if (!expectation.matchHeaders(headers)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we are now not throwing the if
block above, this should be an else if
.
(Is there a test that catches this?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now, there is. :) It breaks nothing. If both data and headers don't match, we still get an error. Do you insist on I brought else if
?throw
s back.
d548e10
to
490d1f7
Compare
Okay, okay, fixed it too. |
483201b
to
377bff8
Compare
@gkalpak Please have a look. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there 😃
src/ngMock/angular-mocks.js
Outdated
@@ -1510,16 +1510,25 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) { | |||
} | |||
} | |||
|
|||
function createFatalError(message) { | |||
var error = new Error(message); | |||
// In addition to be being converted to a rejection, these errors also need to be passed to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
be being --> being
|
||
it('should throw error when response is not defined for a backend definition', function() { | ||
expect(function() { | ||
hb.whenGET('/some'); // no .respond(...) ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😱 😛
test/ngMock/angular-mocksSpec.js
Outdated
hb.expectPOST('/some', {foo: 1}, {X: 'val1'}).respond({}); | ||
hb('POST', '/some', {foo: 2}, callback, {X: 'val2'}); | ||
hb.flush(); | ||
}).toThrowError(/^Expected POST \/some with different/); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Different what? 😃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it important? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is 😃
It ensures that the data error takes precedence. It is not terribly important, but there is no need to break this behavior in the future (as originally happened in this PR).
c63b090
to
7f6e37f
Compare
This was only partially fixed in angular@f18dd29
7f6e37f
to
b8f8554
Compare
@gkalpak it looks like your change requests have been applied, no? |
This was only partially fixed by f18dd29
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Bug fix,
What is the current behavior? (You can also link to an open issue here)
The test doesn't fail in case of a failed
$httpBackend
expectationWhat is the new behavior (if this is a feature change)?
The test does fail.
Does this PR introduce a breaking change?
No
Please check if the PR fulfills these requirements