JackCA / ember-wait-for-test-helper

Ember waitFor test helper

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ember-wait-for-test-helper

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 { selectorToExists } 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.

test("it should wait before asserting", function(assert) {
  visit("/");

  waitFor(() => {
    let result = getAnswerFromSomewhere();
    return result === 42; // only continue when result is 42
  });

  andThen(() => {
    // ...
  });
});

About

Ember waitFor test helper

License:MIT License


Languages

Language:JavaScript 85.6%Language:HTML 14.4%