在升级到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
的渲染错误,模板的一部分比supplier.prices有{{each}}
。如果我在{{each}}之前将{{log supplier}}放在模板中,那么我会看到undefined
。所以我的猜测是在渲染调用之前没有发生过设置?我需要做些什么来完成这项工作,我不需要在单元测试表格中进行任何回调或等待,我现在可以吗?
答案 0 :(得分:0)
github上的Rwjblue向我指出(https://github.com/ember-cli/ember-cli/issues/4532),你不仅需要设置属性,还必须将它包含在渲染中。将我的测试更改为:
var self = this;
self.set('supplier', supplier);
this.render(hbs`{{widgets/add-update-order-item supplier=supplier}}`);
的工作。