Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example PromiseProxyMixin issue
import Ember from 'ember';
const { inject } = Ember;
export default Ember.Controller.extend({
myService: inject.service(),
appName: 'Ember Twiddle',
});
import Ember from 'ember';
const { run, inject, RSVP: { defer } } = Ember;
export default Ember.Route.extend({
myService: inject.service(),
beforeModel(controller) {
// Load in the background
const deferred = defer('Example Promise');
this.set('myService.promise', deferred.promise);
run.later(() => deferred.resolve("some content"), 1000);
// This seems like it normally wouldn't happen, but it is very common in tests for the application to get destroyed and therefore all objects.
this.get('myService').destroy();
},
});
import Ember from 'ember';
export default Ember.Service.extend(Ember.PromiseProxyMixin, {
});
<h1>PromiseProxyMixin issue</h1>
<br>
<p>
This example is pretty contrived. Normally, I would see this error in acceptance and integration tests, when a component is rendered that calls a service that uses PromiseProxyMixin, or a controller is initialized that uses PromiseProxyMixin, and the test does not need to wait for all promises so it completes and the app is destroyed before the promise resolves.
</p>
<p>
Everything is set up in the routes/application. The error is:
<pre><code>
Error: Assertion Failed: calling set on destroyed object
</code></pre>
Open developer tools to see the error. Comment the last line of `beforeModel` to see PromiseProxyMixin work normally.
</p>
<p>
{{#if myService.isPending}}
Loading
{{else}}
Loaded {{myService.content}}
{{/if}}
</p>
{
"version": "0.10.4",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.7.0",
"ember-data": "2.7.0",
"ember-template-compiler": "2.7.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.