Skip to content

Instantly share code, notes, and snippets.

@jelhan
Last active April 14, 2016 00:00
Show Gist options
  • Save jelhan/a50c05ec5a050a4c72fd3c53445e3e1d to your computer and use it in GitHub Desktop.
Save jelhan/a50c05ec5a050a4c72fd3c53445e3e1d to your computer and use it in GitHub Desktop.
stackoverflow 36602056
import Ember from 'ember';
export default Ember.Component.extend({
tagName: 'p'
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Ember from 'ember';
export function helloWorld(params/*, hash*/) {
return new Ember.Handlebars.SafeString('<strong>Hello World!</strong>');
}
export default Ember.Helper.helper(helloWorld);
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{component-using-helper}}
<br>
<br>
import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';
moduleForAcceptance('TODO: put something here');
test('visiting /', function(assert) {
visit('/');
andThen(function() {
assert.equal(currentURL(), '/');
assert.equal(
find('p').html().trim(),
'<strong>Hello World!</strong>'
);
});
});
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 { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
moduleForComponent('component-using-helper', 'TODO: put something here', {
integration: true
});
test('it renders', function(assert) {
this.render(hbs`{{component-using-helper}}`);
assert.ok(this.$('p').length === 1);
assert.ok(this.$('p strong').length === 1);
assert.equal(this.$('p strong').html().trim(), 'Hello World!');
});
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