Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MockConnection.mockError() should result in a returned Response instead of Error #7135

Closed
justindsmith opened this issue Feb 17, 2016 · 5 comments

Comments

@justindsmith
Copy link

@justindsmith justindsmith commented Feb 17, 2016

In the base implementation of XHRBackend (link) when an error is detected a Response object is created and returned to the observer. In the MockBackend, when mockError() 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 Response object to the mockError() function to get around the problem, but it will break the typescript compiler (lots of warnings).

Suggestion is to either accept a Response object in the mockError() or package the Error into a Response object as is done in the XHRBackend. (I notice that there is already a TODO in the MockConnection class to "consider using Response type".)

@lthoang101
Copy link

@lthoang101 lthoang101 commented Aug 1, 2016

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.
e.g mockError(myResponse as any as Error)

@ckuetbach
Copy link

@ckuetbach ckuetbach commented Sep 21, 2016

This would fix the problem: #8961

@vicb vicb added the comp: http label Sep 22, 2016
@alxhub alxhub added this to Legacy Bugs in Http Apr 1, 2017
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 alxhub moved this from Legacy Bugs to PR Pending in Http Jun 7, 2017
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
@ghost
Copy link

@ghost ghost commented Sep 21, 2017

Any news on this?

@ngbot ngbot bot added this to the Backlog milestone Jan 23, 2018
@splincode
Copy link
Contributor

@splincode splincode commented Jul 30, 2018

@mhevery @justindsmith This issue is relevant?

@alxhub alxhub closed this Aug 8, 2018
@angular-automatic-lock-bot
Copy link

@angular-automatic-lock-bot angular-automatic-lock-bot bot commented Sep 13, 2019

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Http
PR Pending
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants
You can’t perform that action at this time.