Ember 2.15 - Integration tests with rejected promise
See original GitHub issueUsing 2.14.1, I can test both success and failure scenarios work when resolving promises.
Switching to v2.15.0-beta.1 however results in this error:
I was unable to replicate in a Twiddle, so I have created a demo repo instead.
The relevant files are: my-component.js my-component-test.js
Unsure, but might be related to https://github.com/emberjs/ember.js/issues/15490
Issue Analytics
- State:
 - Created 6 years ago
 - Comments:18 (16 by maintainers)
 
Top Results From Across the Web
Ember Integration Test: Promise rejected before it renders
Suddenly some of my other UNRELATED/UNTOUCHED component integration tests stopped working, returning the following error: Promise rejected ...
Read more >RSVP.Promise - 2.15 - Ember API Documentation
Promise objects represent the eventual result of an asynchronous operation. ... A promise can be in one of three states: pending, fulfilled, or...
Read more >[Solved]-How do I create a promise in Ember.js for an Ember ...
Basically you can create a promise like this: var promise = new Ember.RSVP.Promise(function(resolve, reject){ // succeed resolve(value); // or reject ...
Read more >Javascript (Browser & Node.js) - Rollbar Docs
Rollbar.js 2.15.0 and later ... Rollbar.js earlier than 2.15.0 ... Rollbar.js supports the ability to catch and report unhandled Promise rejections, ...
Read more >ember-source | Yarn - Package Manager
Ember.js is a JavaScript framework that greatly reduces the time, effort and resources needed to build any web application. It is focused on...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

OK, I have finally run this issue to ground. It’s a doozy…
The underlying principle in tests is that rejected promises which are not handled within the same run loop trigger the unhandled rejection handler (which by default calls
assert.ok(false, ....)and fails the current test). Generally speaking, this is very desireable ergonomics wise.Given this test (which passes on Ember <= 2.14 and fails on 2.15+):
We can see that the following things are happening:
RSVP.reject('bar')) which queues up the unhandled rejection assertionthis.set(which is essentiallyEmber.run(Ember.set, this, rejectedPromise))this.render(which is ultimately going to instantiate the component with the provided promise, and callpromise.then(handleSuccess, handleFailure))The primary difference between the Ember versions is how the unhandled rejection assertion is delivered.
In Ember <= 2.14 the assertion is queued up to be ran after a flush of the run loop on the next tick (e.g.
setTimeout(flushAndAssert, 0)). Since both2)and3)above are synchronous, this meant that under Ember <= 2.14, the promise rejection was handled by the time the unhandled rejection assertion is ran, and therefore no assertion is made.In Ember 2.15+ (versions which include https://github.com/BackburnerJS/backburner.js/pull/203), the assertion is queued up to be ran after the flush of the next run loop. This means that when the run loop from
2)is ran, the assertion is triggered and therefore the test fails.Unfortunately, I believe the change in behavior is desirable and should remain.
There are a few different ways to successfully test this interaction. I’ve made separate PR’s to the demo repo to show each of them:
Ember.Test.adapter.exceptionto swallow the unhandled rejection assertion: https://github.com/amk221/-ember-rsvp-test-failure/pull/3I missed that there was a demo repo in your intro (sorry about that), I’ll try to poke at this later today…