[英]How to pass only model[0] to a component from the template in Ember?
[英]Pass a model into a component test in ember
我有一個需要模型實例的組件。 型號名稱為WorkflowState。 如何創建workflowstate的實例並注入組件。
我需要使用以下方法創建工作流狀態:
WorkflowState.create('some data')
因為構造函數有一些需要運行的邏輯。
我無法訪問WorkflowState。 我嘗試添加這樣的import語句
import WorkflowState from "../../../app/models/wokrflow-state";
但那沒編譯......
知道我怎么能這樣做嗎?
我的測試看起來像這樣:
var stateString = 'some data';
var state = WorkflowState.create(JSON.parse(stateString));
var component = this.subject({
workflow: {state: state}
});
// do some testing on the component
請幫忙。 謝謝。
理想情況下,組件的測試應與其他單元隔離,如本例中的模型。 您可以傳遞具有測試特定行為所需狀態的假模型。
Ember.Object.create({ // the state you need })
並將其傳遞給組件
如果你真的需要傳遞一個真實的模型,你將不得不做更多的事情,創建一個容器並建立一個商店等,因為你不能直接在模型上調用.create,希望你可以避免所有這些。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.