Skip to content

Instantly share code, notes, and snippets.

@phillipkregg
Last active June 13, 2017 13:11
Show Gist options
  • Save phillipkregg/0de3fed7bac17414a33862fab6037710 to your computer and use it in GitHub Desktop.
Save phillipkregg/0de3fed7bac17414a33862fab6037710 to your computer and use it in GitHub Desktop.
Component Test
import Ember from 'ember';
export default Ember.Component.extend({
actions: {
changeTitle() {
this.set('title', 'clicked!');
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
title: 'Component Title'
});
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
{{str-header
title=title
}}
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
<div class="str-header">
<h1>{{title}}</h1>
<button onclick={{action 'changeTitle'}} class="button">Click Me</button>
</div>
import Ember from 'ember';
export default function destroyApp(application) {
Ember.run(application, 'destroy');
}
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';
const { run } = Ember;
const assign = Ember.assign || Ember.merge;
export default function startApp(attrs) {
let application;
let attributes = assign({rootElement: "#test-root"}, config.APP);
attributes = assign(attributes, attrs); // use defaults, but you can override;
run(() => {
application = Application.create(attributes);
application.setupForTesting();
application.injectTestHelpers();
});
return application;
}
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
moduleForComponent('str-header', 'TODO: put something here', {
integration: true
});
test('it renders', function(assert) {
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.on('myAction', function(val) { ... });
this.render(hbs`{{str-header}}`);
assert.ok(this.$('.str-header')[0]);
});
test('it has a title', function(assert) {
this.set('title', 'STR');
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.on('myAction', function(val) { ... });
this.render(hbs`{{str-header title=title}}`);
assert.equal(this.$('h1').text(), 'STR');
});
test('has click event', function (assert) {
this.set('title', 'STR');
// Mock handler in controller
this.set('clickedController', () => {
this.set('title', 'clicked!');
});
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.on('myAction', function(val) { ... });
this.render(hbs`{{str-header title=title clicked=(action clickedController)}}`);
this.$('.str-header').find('.button').click();
assert.equal(this.$('.str-header').find('h1').text(), 'clicked!');
});
import resolver from './helpers/resolver';
import {
setResolver
} from 'ember-qunit';
setResolver(resolver);
{
"version": "0.12.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.12.0",
"ember-template-compiler": "2.12.0",
"ember-testing": "2.12.0"
},
"addons": {
"ember-data": "2.12.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment