This helper is now built-in:
import { waitFor, waitUntil } from '@ember/test-helpers';
Wait for your application to be in a specific state before continuing the test runner.
Useful for certain jquery plugins that take time to load. You can now avoid race conditions with a hard-coded wait time.
Add this line to tests/helpers/start-app.js
in your app:
import 'ember-wait-for-test-helper/wait-for';
Now you can do something like:
import { selectorToExist } from 'ember-wait-for-test-helper/wait-for';
test('it should wait before asserting', function(assert) {
click('.button');
waitFor(selectorToExist('.a-slow-jquery-plugin'));
andThen(() => {
assert.ok(find('.a-slow-jquery-plugin').length === 1);
});
});
You can define your own waiters. A waiter is a function that will continuously run until it returns true. Once the waiter returns true your test will continue running. It supports Promises.
test('it should wait before asserting', function(assert) {
visit('/');
waitFor(() => {
let result = getAnswerFromSomewhere();
return result === 42; // only continue when result is 42
});
// or
waitFor(() => {
return getAnswerFromSomewhere(result => {
return result === 42; // only continue when result is 42
});
});
andThen(() => {
// ...
});
});