Skip to content

Instantly share code, notes, and snippets.

@raido
Last active March 16, 2016 15:48
Show Gist options
  • Save raido/7fdf923d89ea37095cf3 to your computer and use it in GitHub Desktop.
Save raido/7fdf923d89ea37095cf3 to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Helper _lookupFactory'
});
<h1>{{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
import Ember from 'ember';
export function helloWorld(params, hash) {
let cents = params[0];
let currency = hash.currency;
return `${currency}${cents * 0.01}`;
}
export default Ember.Helper.helper(helloWorld);
import Ember from 'ember';
export default Ember.Route.extend({
model() {
let things = [];
for (let i = 0; i < Math.ceil(Math.random() * 1000); i++) {
things.push(i);
}
return things;
}
});
{{#link-to 'other' id="other-link"}}Other route{{/link-to}}
<h3>Index</h3>
{{#each model as |cents|}}
<p>{{format-currency cents currency="$"}}</p>
{{/each}}
import Ember from 'ember';
export default Ember.Route.extend({
model() {
let things = [];
for (let i = 0; i < Math.ceil(Math.random() * 1000); i++) {
things.push(i);
}
return things;
}
});
<h3>Other</h3>
{{#link-to 'index' id="index-link"}}Index route{{/link-to}}
{{#each model as |cents|}}
<p>{{format-currency cents currency="$"}}</p>
{{/each}}
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: 'none'
});
Router.map(function() {
this.route('other');
});
export default Router;
import { test } from 'qunit';
import Ember from 'ember';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';
moduleForAcceptance('TODO: put something here');
const RUNS = 100;
test('visiting / and /other via link clicks', function(assert) {
assert.expect(0);
let done = assert.async();
visit('/');
function repeat(count) {
console.log("Sample: ", count);
click('#other-link');
click('#index-link');
andThen(function() {
if (count > RUNS) {
done();
} else {
Ember.run.later(function() {
repeat(count+1);
}, 1001);
}
});
}
andThen(function() {
repeat(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": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.1/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.2/ember.prod.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