Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upMockConnection.mockError() should result in a returned Response instead of Error #7135
Comments
|
I was facing the same issue. The temporary workaround that I've come up with is to do a double cast of type Response to type Error. |
|
This would fix the problem: #8961 |
alxhub
added a commit
to alxhub/angular
that referenced
this issue
Jun 7, 2017
Previously, MockConnection.mockError() only accepted an Error object. However, in @angular/http, unsuccessful Responses are returned on the error stream. Without this change, there is no easy way to mock an unsuccessful Response. This changes mockError() to also accept the Response type. Fixes angular#12857 Fixes angular#7135
alxhub
added a commit
to alxhub/angular
that referenced
this issue
Jun 7, 2017
Previously, MockConnection.mockError() only accepted an Error object. However, in @angular/http, unsuccessful Responses are returned on the error stream. Without this change, there is no easy way to mock an unsuccessful Response. This changes mockError() to also accept the Response type. Fixes angular#12857 Fixes angular#7135
|
Any news on this? |
|
@mhevery @justindsmith This issue is relevant? |
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
In the base implementation of
XHRBackend(link) when an error is detected aResponseobject is created and returned to the observer. In theMockBackend, whenmockError()is called, the error is directly passed to the observer (link).This means error use cases can't be easily tested because the error payload object will be different between browser and testing.
In the mean time you can pass a
Responseobject to themockError()function to get around the problem, but it will break the typescript compiler (lots of warnings).Suggestion is to either accept a
Responseobject in themockError()or package theErrorinto aResponseobject as is done in theXHRBackend. (I notice that there is already a TODO in theMockConnectionclass to "consider using Response type".)