Skip to content

Instantly share code, notes, and snippets.

@hoodwink73
Created September 26, 2017 10:25
Show Gist options
  • Select an option

  • Save hoodwink73/47df520d63f890e9ec62baa9dbe61f12 to your computer and use it in GitHub Desktop.

Select an option

Save hoodwink73/47df520d63f890e9ec62baa9dbe61f12 to your computer and use it in GitHub Desktop.
Intergration tests with Components Examples
import Ember from 'ember';
export default Ember.Component.extend({
'title': 'Hello World',
actions: {
updateTitle () {
this.set('title': 'This is magic')
}
}
});
import Ember from 'ember';
export default Ember.Component.extend({
attributeBindings: ['style'],
style: Ember.computed('name', function () {
const name = this.get('name');
return `color: ${name}`;
})
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
<h2>{{title}}</h2>
<button class="title-button" {{action "updateTitle"}}>
Update Title
</button>
{{yield}}
Pretty Color: {{name}}
{{yield}}
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('magic-title', 'Check magic title toggle check', {
integration: true
});
test('it renders', function(assert) {
assert.expect(2);
this.render(hbs`{{magic-title}}`);
assert.equal(this.$('h2').text(), 'Hello World', 'initial text is hello world');
Ember.run(() => document.querySelector('.title-button').click());
assert.equal(this.$('h2').text(), 'This is Magic', 'title changes after click')
});
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
moduleForComponent('pretty-color', 'TODO: put something here', {
integration: true
});
test('should change colors', function(assert) {
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.on('myAction', function(val) { ... });
assert.expect(2);
this.set('colorValue', 'red');
this.render(hbs`{{pretty-color name=colorValue}}`);
assert.equal(this.$('div').attr('style'), 'color: red', 'starts as red');
this.set('colorValue', 'blue');
assert.equal(this.$('div').attr('style'), 'color: blue', 'updates as blue');
});
import resolver from './helpers/resolver';
import {
setResolver
} from 'ember-qunit';
setResolver(resolver);
{
"version": "0.12.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": true
},
"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