Skip to content

Instantly share code, notes, and snippets.

@iezer
Created April 26, 2016 21:38
Show Gist options
  • Save iezer/1eb19633a4dd3d6cdc9274c36f067fa7 to your computer and use it in GitHub Desktop.
Save iezer/1eb19633a4dd3d6cdc9274c36f067fa7 to your computer and use it in GitHub Desktop.
slow promise testing
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
text: 'nothing',
p1() {
return new Ember.RSVP.Promise((resolve, reject) => {
let delay = 10; // <= 10 passes, > 10 fails
// doesn't matter if you resolve or rejectt
setTimeout(resolve, delay);
});
},
p2() {
return this.p1().then(() => {
console.log('shouldnt go here');
}, () => {
console.log('rejected');
return 2;
});
},
p3() {
return this.p2().then(() => {
this.set('text', 'clicked');
});
},
actions: {
click() {
this.p3();
}
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
<button {{action "click"}}>click me</button>
<p>{{text}}</p>
<br>
<br>
import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';
moduleForAcceptance('TODO: put something here');
test('visiting /my-acceptance', function(assert) {
assert.expect(1);
visit('/');
click('button')
andThen(function() {
assert.equal(find('p:contains(clicked)').length, 1, 'clicked found');
});
});
import Ember from 'ember';
export default function destroyApp(application) {
Ember.run(application, 'destroy');
}
import { module } from 'qunit';
import startApp from '../helpers/start-app';
import destroyApp from '../helpers/destroy-app';
export default function(name, options = {}) {
module(name, {
beforeEach() {
this.application = startApp();
if (options.beforeEach) {
options.beforeEach.apply(this, arguments);
}
},
afterEach() {
if (options.afterEach) {
options.afterEach.apply(this, arguments);
}
destroyApp(this.application);
}
});
}
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 Ember from 'ember';
import Application from '../../app';
import config from '../../config/environment';
export default function startApp(attrs) {
let application;
let attributes = Ember.merge({rootElement: "#test-root"}, config.APP);
attributes = Ember.merge(attributes, attrs); // use defaults, but you can override;
Ember.run(() => {
application = Application.create(attributes);
application.setupForTesting();
application.injectTestHelpers();
});
return application;
}
import resolver from './helpers/resolver';
import {
setResolver
} from 'ember-qunit';
setResolver(resolver);
{
"version": "0.7.2",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": true
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.4/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.4.3/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.4/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment