我试图创建一个简单的测试来创建新记录。
test('Create dataset', function(assert) {
expect(1);
visit('/add');
fillIn('input.name', 'some name');
fillIn('input.description', 'some description');
//this part is to click on custom dropdown and select first option
click('.select2-container input'); //after this action a list of options is generated
click('.select2-drop ul li:first'); //but this action runs before the list was generated, so it gives me an error that this element does not exist
click('button[type="submit"]');
});
有没有办法暂停测试,直到列表呈现为?
例如waitFor(' .select2-drop ul li:first')
UPD:我发现select2将其下拉列表生成为' body'。 Ember测试在div#ember-testing中运行。这就是为什么我的测试脚本没有看到select2的内容。
答案 0 :(得分:2)
要处理异步行为,请使用andThen
帮助程序
test('Create dataset', function(assert) {
expect(1);
visit('/add');
andThen(function() {
fillIn('input.name', 'some name');
fillIn('input.description', 'some description');
//this part is to click on custom dropdown and select first option
click('.select2-container input'); //after this action a list of options is generated
click('.select2-drop ul li:first'); //but this action runs before the list was generated, so it gives me an error that this element does not exist
click('button[type="submit"]');
});
});