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

[BUG] RSVP's different onerrorDefault behaviour in testing breaks tests #12567

Closed
kevinansfield opened this issue Nov 6, 2015 · 7 comments
Closed

Comments

@kevinansfield
Copy link
Contributor

In trying to test our 401 error handling in our application route's error action I found that it was working fine in development the the adapter error successfully handled/supressed but in our tests the DS.AdapterError was always being output before our error handler is reached.

In short:

  • In development/production, errors in RSVP are thrown normally and can be handled/suppressed by route error actions
  • Inside of testing, errors in RSVP are output immediately leaving route error hooks unable to suppress the error which results in failing tests

I tracked the problem down to https://github.com/emberjs/ember.js/blob/v1.13.10/packages/ember-runtime/lib/ext/rsvp.js#L54:L65 which has different behaviour when in the test environment.

To workaround the RSVP's test behaviour, in any tests where we are expecting adapter errors to be handled in route error actions we have to disable/enable RSVP's error handling:

...
// copy onerrorDefault from https://github.com/emberjs/ember.js/blob/v1.13.10/packages/ember-runtime/lib/ext/rsvp.js

describe('Acceptance: Authentication', function () {
    beforeEach(function () {
        Ember.RSVP.off('error');
    });

    afterEach(function () {
        Ember.RSVP.on('error', onerrorDefault);
    });

    ...
});

This is quite non-obvious behaviour - I would expect the error handling flow to be the same in my tests as it is in development.

Possibly related: #12547, #12472, #12166, teddyzeenny/ember-mocha-adapter#34

Ember version: 1.13.10
Ember Data version: 1.13.13

@rwjblue
Copy link
Member

rwjblue commented Nov 6, 2015

I believe that #12549 will fix this issue. Can you test?

@kevinansfield
Copy link
Contributor Author

I've tested against #12549 - the order has changed as the error action on the application route is hit first but the DS.AdapterError is still output and breaks the test.

@rwjblue
Copy link
Member

rwjblue commented Nov 6, 2015

Hmm. Does your error action return true?

@kevinansfield
Copy link
Contributor Author

https://github.com/kevinansfield/Ghost/blob/rsvp-error-fix-test/core/client/app/routes/application.js#L139

It return false if it handles the error but true by default to keep bubbling as per http://emberjs.com/api/classes/Ember.Route.html#toc_bubbling. However, returning either true/false results in the same issue.

@kevinansfield
Copy link
Contributor Author

Just had a thought - is there any chance this could be ember-mocha/ember-mocha-adapter related? I would have thought more people would be running into this issue if it's a bug within ember itself, especially as the referenced bugfix says <2.1 is ok...

@kevinansfield
Copy link
Contributor Author

Closing this, I think our tests were hitting a slightly different path than I thought 🙄

@rwjblue
Copy link
Member

rwjblue commented Nov 9, 2015

kk, please ping me if you want another set of eyes on it....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants