angular icon indicating copy to clipboard operation
angular copied to clipboard

Problems mocking MockConnection error response

Open denchdev opened this issue 10 years ago • 7 comments

I'm testing http service in Angular2. I want to test the server, the server responds 'Unauthorized Error'. In test I used this code:

this.backend.connections.subscribe(
            (connection: MockConnection) => {
                console.log("Connection");
                connection.mockError(<any>new Response(new ResponseOptions({status: 401, body: 'error'})));
            }
        );

In test I used handleError from angular.io..

It is the wrong decision. Tell me how to test this situation.

denchdev avatar Mar 07 '16 23:03 denchdev

Hi,

So the problem is that MockConnection method to mock error response accepts an instance of Error which does not allow to pass response object to error handler. Cast to any allows to bypass type checks so we can finally pass the response, but to me it looks like a dirty hack.

Is this a bug in MockConnection API or do we do something wrong?

Thank you, Roman

RomanKisilenko avatar Mar 09 '16 10:03 RomanKisilenko

+1 interested on this.

leovrf avatar Mar 15 '16 16:03 leovrf

Anyone have a solution to this yet?

cbomkamp avatar May 23 '16 19:05 cbomkamp

+1 ... bump

dkro avatar Sep 23 '16 13:09 dkro

Could somebody add a minimal repro ? thanks

vicb avatar Oct 04 '16 16:10 vicb

Thanks for reporting this issue. However, you didn't provide sufficient information for us to understand and reproduce the problem. Please check out our submission guidelines to understand why we can't act on issues that are lacking important information.

If the problem still persists, please file a new issue and ensure you provide all of the required information when filling out the issue template.

pkozlowski-opensource avatar Oct 09 '16 08:10 pkozlowski-opensource

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.