Created
September 26, 2017 10:25
-
-
Save hoodwink73/47df520d63f890e9ec62baa9dbe61f12 to your computer and use it in GitHub Desktop.
Intergration tests with Components Examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Ember from 'ember'; | |
| export default Ember.Component.extend({ | |
| 'title': 'Hello World', | |
| actions: { | |
| updateTitle () { | |
| this.set('title': 'This is magic') | |
| } | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Ember from 'ember'; | |
| export default Ember.Component.extend({ | |
| attributeBindings: ['style'], | |
| style: Ember.computed('name', function () { | |
| const name = this.get('name'); | |
| return `color: ${name}`; | |
| }) | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Ember from 'ember'; | |
| export default Ember.Controller.extend({ | |
| appName: 'Ember Twiddle' | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Ember from 'ember'; | |
| export default function destroyApp(application) { | |
| Ember.run(application, 'destroy'); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Resolver from '../../resolver'; | |
| import config from '../../config/environment'; | |
| const resolver = Resolver.create(); | |
| resolver.namespace = { | |
| modulePrefix: config.modulePrefix, | |
| podModulePrefix: config.podModulePrefix | |
| }; | |
| export default resolver; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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') | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import resolver from './helpers/resolver'; | |
| import { | |
| setResolver | |
| } from 'ember-qunit'; | |
| setResolver(resolver); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "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