Skip to content

Instantly share code, notes, and snippets.

@pavloo
Last active March 16, 2016 23:21
Show Gist options
  • Save pavloo/9f7ee38e2c57c3bec0f6 to your computer and use it in GitHub Desktop.
Save pavloo/9f7ee38e2c57c3bec0f6 to your computer and use it in GitHub Desktop.
registerWaiter illustartion
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
actions: {
insert(){
// set timeout is used intentionally
// (instead of Ember.run.later)
setTimeout(()=>{
Ember.$("#container").append("<p>HI</p>");
}, 1000);
}
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
<button {{action 'insert'}}>Click</button>
<div id="container"></div>
{{outlet}}
<br>
<br>
import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';
moduleForAcceptance('TODO: put something here');
test('with registerWaiter', function(assert) {
const waiterFunc = function(){
return find("p").length === 1;
};
visit('/');
andThen(()=>{
Ember.Test.registerWaiter(this, waiterFunc);
click('button');
andThen(()=>{
assert.equal(find('p').length, 1);
Ember.Test.unregisterWaiter(this, waiterFunc);
})
});
});
test('without registerWaiter', function(assert) {
visit('/');
andThen(()=>{
Ember.Test.registerWaiter(()=>{
return find("p").length === 1;
});
click('button');
andThen(()=>{
assert.equal(find('p').length, 1);
})
});
});
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.6.4",
"EmberENV": {
"FEATURES": {}
},
"options": {
"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.1/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.4.0/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.1/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment