【发布时间】:2014-08-30 15:10:41
【问题描述】:
我目前正在尝试在 ember 中对控制器上的计算属性进行单元测试。我在控制器上有一个活动模型,活动有很多问题。计算属性检查是否有关于活动的问题。测试代码和控制器如下:
测试:
test("questionLength property", function() {
expect(2);
var controller = App.__container__.lookup('controller:campaignDeployment');
var store = controller.get('store');
var campaign = store.createRecord('campaign', {id: 500});
Ember.run(function() {
controller.set('model', campaign);
equal(controller.get('questionsLength'), 0, 'should not have question length');
campaign.get('questions').then(function() {
campaign.get('questions').pushObject(store.createRecord('question', {
id: 678,
text: 'Test Question',
link: 'http://www.jebbit.com'
}));
});
controller.set('model', campaign);
equal(controller.get('questionsLength'), 1, 'should have question length');
});
});
控制器和属性:
App.CampaignDeploymentController = Em.ObjectController.extend({
questionsLength: function() {
return this.get('content.questions.length');
}.property('content.questions.[]'),
});
问题是,控制器上存在广告系列,但问题不是。关于为什么第二个断言没有通过的任何想法?
【问题讨论】: