0

我正在使用 ember-cli qunit 测试moduleForComponent。我在创建的 ember 组件中有以下选择元素。

        {{input site as="select"
            collection="sites"
            selection="site"
            optionLabelPath="content.siteLabel"
            optionValuePath="content.id"
            prompt="Please Select"
            label=" "
        }}

使用. sites_store

sites : function() {
    return this.get('store').find('site');
}.property()

我正在使用jsMockito来模拟store.

var siteMock = mock(DS.Model);
when(siteMock).get('id').thenReturn(1);
when(siteMock).get('siteLabel').thenReturn('Qunit');

var storeMock = mock(DS.Store);
when(storeMock).find('site').thenReturn([siteMock]);

我将它作为测试中的参数传递给组件。

var component = this.subject({
    store : storeMock
});

生成的 html 看起来像这样,似乎 siteMock 已呈现,但即使我在模拟上添加了适当的期望 optionLabelPath,也无法正常工作。optionValuPath

<select id="ember473" class="ember-view ember-select">
    <option value="">Please Select</option>
    <option id="ember491" class="ember-view" value=""></option>
</select>

我已经siteMock在调试器中使用 getter 进行了测试,一切都按预期工作。我想我需要when对某些属性的另一个条件,siteMock但我不确定是什么。任何人都可以给我一些关于让这个工作的建议吗?

4

1 回答 1

0

问题似乎是您在考虑将控制器代理到模型content.的路径中使用。optionLabelPath="content.siteLabel"

但是您的测试直接使用模型 - 未由控制器修饰 - 并且它们没有 content 属性。

于 2014-11-19T15:23:06.587 回答