在升级到 Ember CLI 1.13.1 之前,所有组件都生成了一个单元测试,如果我的组件依赖于一个属性,我可能会编写如下内容:
var supplier = var supplier = Ember.ObjectProxy.create({
...
});
// Creates the component instance
var component = this.subject();
assert.equal(component._state, 'preRender');
component.set('supplier', supplier);
// Renders the component to the page
this.render();
assert.equal(component._state, 'inDOM');
这将通过/渲染一切正常。
我现在正在为此编写一个集成测试,如下所示:
var self = this;
Ember.run(function() {
self.set('supplier', supplier);
});
this.render(hbs`{{widgets/add-update-order-item}}`);
我遇到的问题是渲染错误Cannot read property 'forEach' of undefined
,部分模板的{{each}}
供应商价格过高。如果我在 {{each}} 之前的模板中放置一个 {{log supplier}},那么我会看到undefined
. 所以我的猜测是在渲染调用之前设置没有发生?我需要做些什么才能使其正常工作,我不需要任何回调或在单元测试表单中等待,是吗?