I'm developing a small application in Ember.js and I'm having some troubles trying to unit test it. I have the following code:
// app/models/book.js
export default DS.Model.extend({
name: DS.attr('string'),
author: DS.attr('string'),
rating: DS.attr('number'),
category: DS.belongsTo('category', {
async: true
})
});
// app/models/category.js
export default DS.Model.extend({
name: DS.attr('string'),
bestRated: function () {
return this.get('books').sortBy('rating').reverse();
}.property('books.@each'),
books: DS.hasMany('modules', {
async: true
})
});
// tests/unit/models/category-test.js
moduleForModel('category', 'Category Model', {
needs: ['model:book']
});
test('category bestRated ... ok', function (assert) {
var category = this.subject();
// I want to populate category.modules with test modules,
// but I don't know how to do it.
// If I try to use Ember.Object or Ember.ObjectProxy,
// the test won't pass saying that cannot populate
// with undefined, only book is allowed
});
How can I create test books to test category?
Aucun commentaire:
Enregistrer un commentaire