EmberJS测试:从每个循环创建目标id



我使用了一个each循环为创建的每个输入创建一个唯一的id。例如:id='amount0'id='amount1'等。但在测试过程中我不能瞄准它们,它说找不到元素。

错误

Promise rejected during "Amount input works": Element not found when calling `fillIn('#amount0')`.

HBS文件:

{{#each userInfo as |user index|}}
<p output-test-info>
<button onclick={{action clearEverything index}}>-</button>
{{user.name}}
<input id="amount{{index}}" onchange={{action (action addAmount index) value="target.value"}}>
</p>
{{/each}}

测试文件:

test('Amount input works', async function(assert){
const itemList = document.queryCommandValue('output-test-info');
this.set('tempName', [{name: 'bobby'}, {name: 'peter'}]);
this.set('tempAct', [{activity: 'dinner'}, {activity: 'movies'}])
await render(hbs`<Output @userinfo={{this.tempArray}} @userAct={{this.tempAct}}/>`);
await fillIn('#amount0', '20');
})

错误显然在这里@userinfo={{this.tempArray}}。没有这个变量,只有tempNametempAct。很可能tempName就在那里。

最新更新