-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Test.adapter.exception forces acceptance test to fail (RSVP error fails test) #12791
Comments
@rwjblue, @stefanpenner does this look related: #11903 and #11469 seems like this issue has the same root cause "RSVP Error failing the test" |
This sounds like a symptom, not a root cause. |
So it appears their is a legitimate failure, but it is confusing that their is no-obvious way to handle it and retain the error page. |
some relevant docs https://github.com/emberjs/ember.js/blob/master/packages/ember-routing/lib/system/route.js#L632-L685 But it does not appear like an obvious solution. @machty how does one gracefully handle such an exception? |
Presently if you don't handle the error with an In general we need to solve the problem of substate testability (a lot of the issues stem from the default behavior of waiting for the entire route transition promise chain to complete), but in the meantime you might consider the following workaround on your application route:
This basically tells Ember the error has been "handled" while preserving the default behavior. The big downside is that if you have a nested error substate template defined, it'll be ignored, since this error hook will run first before Ember tries to find the most specific error substate route. Hmm... I'm not really sure the best way to go with this one. |
@machty @stefanpenner what about an ember-testing method that will allow you to set the test "exception" handler - Perhaps
Also, here is some documentation on how I'm using error substates. |
I've been stuck on this while upgrading Ember. I could solve it with your workaround code. Thank you @pixelhandler ! |
Currently a solution for this issue is just to overwrite Ember.Test.Adapter.exception which provides a public API for this purpose. I think, the problem comes up with the use of the default Ember.Test.Adapter which throw an exception on a promise rejection and it will make the test to fail. IMO, this should not be the default behaviour for acceptance tests. Some possible improvements could be:
cc / @rwjblue |
@ppcano Yeah this example seems usable: let adapterException;
beforeEach() {
this.application = startApp();
adapterException = Ember.Test.adapter.exception;
Ember.Test.adapter.exception = () => null;
},
afterEach() {
Ember.Test.adapter.exception = adapterException;
Ember.run(this.application, 'destroy');
} |
I adapted this code and put it in I’m only just encountering this fix now, but I hope I can come up with a way to mark an exception as expected for particular tests to still have the fail-on-error for unexpected exceptions. |
I found today that this override caused a false positive in my acceptance tests. I use It turns out I only had one test that needed this override, one that tests handling of a 500 from the API. So I’m able to narrowly apply the override to just that test. Cautionary tale! |
Relevant SO: http://stackoverflow.com/questions/34074386/how-to-test-ember-error-substate-with-ember-cli-test-runner tl;dr: my solution was similar to @pixelhandler's here, but using Sinon. See Gist. |
open issue in ember.js emberjs/ember.js#12791
open issue in ember.js emberjs/ember.js#12791
open issue in ember.js emberjs/ember.js#12791
@john-kurkowski yeah thx, so there are more than one way to work-around the test bug. @rwjblue Do you think it's worth calling this a BUG ? or Do we just treat this as something that needs Documentation for work-arounds?
@locks what do you think about documenting work-arounds, seems odd to to that but if we don't call this a bug then that is the only resolution. |
In order to avoid the problem that @backspace encountered, I modified the code @pixelhandler provided:
|
Thank you @pixelhandler and @aquamme. I have taken your code, generalised it into a module and published it as https://gist.github.com/pablobm/5ec0fee8a877badaca2c11bf4751e857 |
I'm going to close this in favor of just using the work around. |
It may help someone: in my case I had to use
instead of
t |
overriding With an helper like
You can target user interactions that will throw exceptions with
There is surely a better way to implement this but this works fine for me. |
It's 2020, and I'm having this issue in every project I have, including Octane. I've also seen people asking about it. We solve it by overriding I believe this is not how it should be done in 2022/Octane. Please reopen. |
Related: emberjs/ember-qunit#592 |
Yep, I think this is the correct way to go. Docs are here: https://github.com/emberjs/ember-test-helpers/blob/master/API.md#setuponerror |
My workaround is here: emberjs/guides#1157 at first I thought it may be best to address with an update to testing guides, but not so sure that is the best way to fix.
Steps to reproduce:
Here is an example repository with an Ember CLI app: https://github.com/pixelhandler/application-error-test
(Can't be done w/ a jsbin/fiddle/ember-twiddle - since this issue is with the testing env.)
Below are the steps I used to create the example app.
{{model.message}}
since the error will become the model via application-error route's setupController hook.visit('/'); andThen(function(){ assert.equal(find('.error-message').length(), 1); });
Expected Result:
The test passes even though an error was thrown in the route's model hook by the mocked 502 response.
Actual Result:
The Assertion passes as the template is rendered, but the test fails since
Test.adapter.exception
is called. Which throws, and causes the test to fail - as a result of the "same" expected error that causes the application-error substate to render.Attempts to solve:
name
property ofTransitionAborted
. This is the code fails the test for the applicaiton-error.hbs template -> https://github.com/emberjs/ember.js/blob/master/packages/ember-runtime/lib/ext/rsvp.js#L66 (this works but is a hack)Ember.Test.QUnitAdapter
and redefinedexception
as the example below:Because an error is thrown and the env is
testing
- Ember RSVP callsTest.adapter.exception
. Which fails the test; because there was an error (we expected an error to be handled by the application-error route/controller/template and it was). In the acceptance test, usingassert.throws
will not help since it's async.I found that I had to reopen my test adapter in the acceptance test like so:
tests/acceptance/application-error-test.js
Pseudo application code
templates/application-error.hbs
routes/application.js
Be sure to see the README of the example repo. This is the commit that shows the setup for the example app.
The text was updated successfully, but these errors were encountered: