Skip to content

(fix) MockCOnnection.mockError also accepts a Response#8961

Closed
nexus-uw wants to merge 1 commit intoangular:masterfrom
nexus-uw:fix/mock-backend-error-accepts-response
Closed

(fix) MockCOnnection.mockError also accepts a Response#8961
nexus-uw wants to merge 1 commit intoangular:masterfrom
nexus-uw:fix/mock-backend-error-accepts-response

Conversation

@nexus-uw
Copy link
Copy Markdown

@nexus-uw nexus-uw commented Jun 2, 2016

  • updates check if the PR fulfills these requirements**
  • The commit message follows our guidelines: https://github.com/angular/angular/blob/master/CONTRIBUTING.md#commit-message-format
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
    fix + resolves a TODO in the code base

Does this PR introduce a breaking change?

  • No
  • What is the current behavior? (You can also link to an open issue here)
    MockConnection.mockError only accepts an Error
  • What is the new behavior (if this is a feature change)?
    MockConnection.mockError now also accepts a Response object (so that people can test non-200 level status codes in their responses

- updatedse check if the PR fulfills these requirements**
- [x] The commit message follows our guidelines: https://github.com/angular/angular/blob/master/CONTRIBUTING.md#commit-message-format
- [x] Tests for the changes have been added (for bug fixes / features)

* **What kind of change does this PR introduce?** (Bug fix, feature, docs update, ...)
fix + resolves a TODO in the code base

* **What is the current behavior?** (You can also link to an open issue here)
MockConnection.mockError only accepts an Error

* **What is the new behavior (if this is a feature change)?**
MockConnection.mockError now also accepts a Response object (so that people can test non-200 level status codes in their responses
@nexus-uw nexus-uw force-pushed the fix/mock-backend-error-accepts-response branch from 6e6e04f to 26b43c6 Compare June 2, 2016 17:26
@nexus-uw
Copy link
Copy Markdown
Author

nexus-uw commented Jun 2, 2016

note: travis CI build is failing due a change in the public API
screen shot 2016-06-02 at 15 28 45

@mhevery
Copy link
Copy Markdown
Contributor

mhevery commented Jun 9, 2016

already merged as c5d8e1e777e67ea3ba6ca5fb85e8d63032510dd0

@mhevery mhevery closed this Jun 9, 2016
@nexus-uw nexus-uw deleted the fix/mock-backend-error-accepts-response branch June 10, 2016 14:14
@paulcadman
Copy link
Copy Markdown

We can't find c5d8e1e777e67ea3ba6ca5fb85e8d63032510dd0 in the repository - was this PR merged? We'd like this fix for our tests.

@ckuetbach
Copy link
Copy Markdown

@mhevery
This is still not possible in 2.0.0 final.

MockBackend, Line 101

@amay0048
Copy link
Copy Markdown

amay0048 commented Oct 4, 2016

+1 for this, it currently means that the mocks don't replicate server interaction correctly

@vicb
Copy link
Copy Markdown
Contributor

vicb commented Oct 4, 2016

Could someone please re-open a PR if this is still a pb (can not re-open this one as the beanch has been deleted).

Thanks.

@amay0048
Copy link
Copy Markdown

amay0048 commented Oct 5, 2016

You can actually extend Response and implement Error to get this working:

import { Response, ResponseOptions, ResponseType, Request } from '@angular/http';
import { MockConnection } from '@angular/http/testing';

class MockError extends Response implements Error {
    name:any
    message:any
}

...
handleConnection(connection:MockConnection) {
    let body = JSON.stringify({key:'val'});
    let opts = {type:ResponseType.Error, status:404, body: body};
    let responseOpts = new ResponseOptions(opts);
    connection.mockError(new MockError(responseOpts));
}

@gkohen
Copy link
Copy Markdown

gkohen commented Oct 7, 2016

@amay0048, does the above code passes compilation for you considering MockError does not have all the properties required by RequestOptions?

@amay0048
Copy link
Copy Markdown

Yes, it compiles for me. It inherits all the properties of response via the extends.

@emersonf
Copy link
Copy Markdown

@amay0048 thanks for the suggestion, works for me.

From a naming standpoint, I went with ErrorResponse. Code then looks like...

class ErrorResponse extends Response implements Error {
    name: any
    message: any
}
...
        if (...) {
            console.info("login successful");

            c.mockRespond(new Response(new ResponseOptions({
                body: {},
                status: 200
            })));
        }
        else {
            console.info('login failed');

            c.mockError(new ErrorResponse(new ResponseOptions({
                body: {},
                status: 401
            })));
        }

@JohannesRudolph
Copy link
Copy Markdown

Just stumbled across this. The pull request should be indeed reopened.

@DzmitryShylovich
Copy link
Copy Markdown
Contributor

#13104

@royling
Copy link
Copy Markdown
Contributor

royling commented Mar 6, 2017

so no plan to merge this change? #13104 is also closed without merging.

@angular-automatic-lock-bot
Copy link
Copy Markdown

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 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.