Reputation: 135
I'm trying to create a simple test for creating of new record.
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"]');
});
Is there any way to pause the test untill the list as rendered?
For example something like waitFor('.select2-drop ul li:first')
UPD: I found out that select2 generated its dropdown list into 'body'. Ember tests are run in div#ember-testing. That is why my test script does not see content of select2.
Upvotes: 0
Views: 212
Reputation: 1264
To handle async behaviours, use the andThen
helper
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"]');
});
});
Upvotes: 2