2015-07-13 47 views
0

之前升级到灰烬CLI 1.13.1所有组件生成一个单元测试,如果我的组件依赖于我可能已经写过类似的属性:如何使用ObjectProxy将Ember单元测试转换为集成测试?

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'); 

,这将通过/渲染一切ok。

我现在正在写一个集成测试此像这样:

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}}超过supplier.prices。如果我在{{each}}之前的模板中放置{{log supplier}},那么我会看到undefined。所以我的猜测是这个集合在渲染调用之前没有发生过?我需要做些什么才能使这个工作,我不需要任何回调或在单元测试表单中等待,现在呢?

回答

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}}`); 

工作。

相关问题