Код из моего controllers/cart.js:
export default Ember.Controller.extend({
cartTotal: Ember.computed('[email protected]', function() {
return this.model.reduce(function(subTotal, product) {
var total = subTotal + product.get('subTotal');
return total;
}, 0);
})
)};
Это вычисляемое свойство перебирает все элементы модели, добавляя все значения свойства subTotal
и возвращая cart total
.
cart-test.js
import { moduleFor, test } from 'ember-qunit';
import Ember from 'ember';
moduleFor('controller:cart', {
// Specify the other units that are required for this test.
// needs: ['controller:foo']
});
test('it exists', function(assert) {
var controller = this.subject();
assert.ok(controller);
});
test('cartTotal function exists', function(assert) {
var controller = this.subject();
assert.equal(controller.get('cartTotal'), 30, 'The cart total function exists');
});
Тест завершается ошибкой с TypeError: Cannot read property 'reduce' of null
, потому что у него явно нет модели для цикла.
Как я могу смоделировать зависимости вычисляемого свойства cartTotal
, чтобы тест прошел?
Спасибо!