Last active
May 10, 2016 14:00
-
-
Save NullVoxPopuli/58a4616a92c5a4d2220db59c86a64ad7 to your computer and use it in GitHub Desktop.
Unit Test Component?
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({ | |
classNameBindings: [ | |
'hasError:error:no-error', 'classes', | |
], | |
errors: [], | |
includeFieldName: false, | |
field: '', | |
hasError: Ember.computed('fieldErrors.@each', function () { | |
let errors = this.get('fieldErrors'); | |
return (errors.length > 0); | |
}), | |
fieldErrors: Ember.computed('errors.@each', 'field', function () { | |
let field = this.get('field'); | |
let error = (this.get('errors.' + field) || []); | |
if (Ember.isEmpty(error)) { | |
return error; | |
} | |
if (Ember.isArray(error)) { | |
if (error.get('firstObject.message') === undefined) { | |
return error.map(e => ({ message: e })); | |
} | |
return error; | |
} | |
return [error]; | |
}), | |
}); |
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 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 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
import { moduleForComponent, test } from 'ember-qunit'; | |
import hbs from 'htmlbars-inline-precompile'; | |
moduleForComponent('my-component', ''); | |
test('it has errors for a field', function() { | |
let component = this.subject(); | |
component.set('field', 'aField'); | |
component.set('errors', { | |
aField: ['an error!'] | |
}); | |
let errors = component.get('fieldErrors'); | |
let result = errors[0].message; | |
let expected = 'an error!'; | |
equal(result, expected); | |
}); | |
test('it has an error', function() { | |
var component = this.subject(); | |
component.set('field', 'aField'); | |
component.set('errors', { | |
aField: { message: 'an error!' } | |
}); | |
let hasError = component.get('hasError'); | |
ok(hasError); | |
}); | |
test('adds the error to the DOM', function() { | |
var component = this.subject(); | |
component.set('field', 'aField'); | |
component.set('errors', { | |
aField: ['an error!'] | |
}); | |
this.append(); | |
equal(this.$().html(), 'an error!'); | |
}); |
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.8.0", | |
"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.5.1", | |
"ember-data": "2.5.2", | |
"ember-template-compiler": "2.5.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment