ember-wait-for-test-helper

3.1.0 • Public • Published

ember-wait-for-test-helper

Deprecated

This helper is now built-in:

import { waitFor, waitUntil } from '@ember/test-helpers';

Greenkeeper badge npm version Build Status Ember Version

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);
  });
});

Custom waiters

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(() => {
    // ...
  });
});

Package Sidebar

Install

npm i ember-wait-for-test-helper

Weekly Downloads

876

Version

3.1.0

License

MIT

Unpacked Size

8.11 kB

Total Files

7

Last publish

Collaborators

  • kellyselden