fake_async 0.1.1 copy "fake_async: ^0.1.1" to clipboard
fake_async: ^0.1.1 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));
    });
  });
}
91
likes
0
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

unknown (LICENSE)

More

Packages that depend on fake_async