fake_async 0.1.2 copy "fake_async: ^0.1.2" to clipboard
fake_async: ^0.1.2 copied to clipboard

outdatedDart 1 only

Fake asynchronous events such as timers and microtasks in order to test for them deterministically and without delay.

fake_async #

Build Status

The fake_async package provides a FakeAsync class which allows one to fake asynchronous events such as timers and microtasks in order to test for them deterministically and without delay.

FakeAsync.run() can be used to execute the test code in a Zone which mocks out the Timer and scheduleMicrotask APIs to instead store their callbacks for execution by subsequent calls to FakeAsync.elapse() which simulates the asynchronous passage of time, which can be measured at any point via FakeAsync.elapsed. The microtask queue is drained surrounding each timer to simulate the real event queue.

For example:

import 'dart:async';

import 'package:fake_async/fake_async.dart';
import 'package:unittest/unittest.dart';

void main() {
  test("Future.timeout() throws an error once the timeout is up", () {
    new FakeAsync().run((async) {
      expect(new Completer().future.timeout(new Duration(seconds: 5)),
          throwsA(new isInstanceOf<TimeoutException>()));
      async.elapse(new Duration(seconds: 5));
    });
  });
}

##Integration with package:clock

It also integrates with the clock package so that now and getStopwatch are consistent with the fake elapsing of time. The FakeAsync constructor takes an initialTime argument to set the initial time.

91
likes
15
pub points
100%
popularity

Publisher

verified publisherdart.dev

Fake asynchronous events such as timers and microtasks in order to test for them deterministically and without delay.

Repository
View/report issues

License

BSD-2-Clause (LICENSE)

Dependencies

clock

More

Packages that depend on fake_async