I have a simple Ember object with a computed function which formats a date, e.g.
import Ember from 'ember';
import DS from 'ember-data';
export default DS.Model.extend({
date: DS.attr('date'),
posted_date: Ember.computed('date', function() {
return this.get('date').toLocaleDateString("en-GB");
})
});
When I test the computed, I weirdly get a failure saying that the the result of get('posted_date')
is a function, qUnit outputs it like this:
Expected:
"2016-05-01"
Result:
function(){
[code]
}
Seems like I'm doing something stupid here but I can't figure it out. The value displays ok in my template, so I think there may just be a problem with the test but I can't see anything wrong with it. The test looks like this:
test('date is formatted to UK format', function(assert) {
const model = this.subject();
Ember.run(function() {
model.set('date', new Date('2016-05-01'));
assert.equal(model.get('posted_date'), '2016-05-01');
});
});
Any thoughts?
Aucun commentaire:
Enregistrer un commentaire