Skip to content

Instantly share code, notes, and snippets.

@cibernox
Forked from amk221/components.my-component.js
Created February 9, 2017 15:57
Show Gist options
  • Save cibernox/4bc98d97cec786951df7d279bfdf280f to your computer and use it in GitHub Desktop.
Save cibernox/4bc98d97cec786951df7d279bfdf280f to your computer and use it in GitHub Desktop.
Promise Proxy integration test
import computed from "ember-computed";
import DS from 'ember-data;
export default Ember.Component.extend({
proxy: computed(function() {
return DS.PromiseProxy.create({
promise: this.getAttr('my-promise')
});
})
});
{{#if proxy.isPending}}
Loading...
{{else if proxy.isRejected}}
Failed: {{proxy.reason.message}}
{{else if proxy.isFulfilled}}
Success: {{proxy.value}}
{{/if}}
import Resolver from '../../resolver';
import config from '../../config/environment';
const resolver = Resolver.create();
resolver.namespace = {
modulePrefix: config.modulePrefix,
podModulePrefix: config.podModulePrefix
};
export default resolver;
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
import RSVP from 'rsvp';
import wait from 'ember-test-helpers/wait';
const { resolve, reject } = RSVP;
moduleForComponent('my-component', {
integration: true
});
test('successful', function(assert) {
this.set('myPromise', resolve({ value: 'Yey!' }));
this.render(hbs`{{my-component my-promise=myPromise}}`);
return wait().then(() => {
assert.equal(this.$().text().trim(), 'Success: Yey!',
'displays success if promise resolves');
});
});
test('unsuccessful (with reason)', function(assert) {
this.set('myPromise', reject({ message: 'Soz :(' }));
// assert.throws(() => {
this.render(hbs`{{my-component my-promise=myPromise}}`);
// });
return wait().catch(() => {
assert.equal(this.$().text().trim(), 'Failed: Soz :(',
'displays error if promise rejects');
});
});
test('unsuccessful (without reason)', function(assert) {
this.set('myPromise', reject());
this.render(hbs`{{my-component my-promise=myPromise}}`);
return wait().then(() => {
assert.equal(this.$().text().trim(), 'Failed:',
'displays error if promise rejects');
});
});
import resolver from './helpers/resolver';
import {
setResolver
} from 'ember-qunit';
setResolver(resolver);
{
"version": "0.11.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": true
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.10.2",
"ember-data": "2.11.0",
"ember-template-compiler": "2.10.2",
"ember-testing": "2.10.2"
},
"addons": {
"ember-cpm": "3.0.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment