Skip to content

An ember shim addon for using lolex

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE.md
Notifications You must be signed in to change notification settings

pfmmfp/ember-cli-lolex-shim

Repository files navigation

ember-cli-lolex-shim

Build Status Ember Observer Score

An ember addon for using lolex fake timer in your tests.

Installation

ember install ember-cli-lolex-shim

Usage

import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';
import { test } from 'qunit';
import lolex from 'lolex';

moduleForAcceptance('Acceptance | lolex');

test('rocket ship launches', function(assert) {

  // install the clock and make the test async
  const clock = lolex.install(),
    done = assert.async();

  // make sure to tick the clock to the next
  // scheduled event when running async code
  // like visit()
  visit('/launch-page');
  clock.next();
  assert.equal(currentURL(), '/launch-page');

  // let's assume this button starts the countdown
  // triggering launch after 10 seconds
  click('button');
  assert.ok(find('.rocket-ship').hasClass('.still-on-earth'));
  
  // fast forward to see the rocket taking off right away
  // (that's eleven seconds from the previous clock time)
  clock.tick(11000);
  assert.ok(find('.rocket-ship').hasClass('.taking-off'));
  
  // uninstall clock and finish async test
  clock.uninstall();
  done();
});

Similar code runs in this acceptance test from our suite.

Development

  • git clone <repository-url> this repository
  • cd ember-cli-lolex-shim
  • npm install
  • bower install

Running

Running Tests

  • npm test (Runs ember try:each to test your addon against multiple Ember versions)
  • ember test
  • ember test --server

Building

  • ember build

For more information on using ember-cli, visit https://ember-cli.com/.