fake_async 1.0.1

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 74

This package provides a FakeAsync class, which makes it easy to deterministically test code that uses asynchronous features like Futures, Streams, Timers, and microtasks. It creates an environment in which the user can explicitly control Dart's notion of the "current time". When the time is advanced, FakeAsync fires all asynchronous events that are scheduled for that time period without actually needing the test to wait for real time to elapse.

For example:

import 'dart:async';

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

void main() {
  test("Future.timeout() throws an error once the timeout is up", () {
    // Any code run within [fakeAsync] is run within the context of the
    // [FakeAsync] object passed to the callback.
    fakeAsync((async) {
      // All asynchronous features that rely on timing are automatically
      // controlled by [fakeAsync].
      expect(new Completer().future.timeout(new Duration(seconds: 5)),
          throwsA(new isInstanceOf<TimeoutException>()));

      // This will cause the timeout above to fire immediately, without waiting
      // 5 seconds of real time.
      async.elapse(new Duration(seconds: 5));
    });
  });
}

Integration With clock

FakeAsync can't control the time reported by new DateTime.now() or by the Stopwatch class, since they're not part of dart:async. However, if you create them using the clock package's clock.now() or clock.getStopwatch() functions, FakeAsync will automatically override them to use the same notion of time as dart:async classes.

1.0.1

  • Update to lowercase Dart core library constants.
  • Fix use of deprecated isInstanceOf matcher.

1.0.0

This release contains the FakeAsync class that was defined in quiver. It's backwards-compatible with both the quiver version and the old version of the fake_async package.

New Features

  • A top-level fakeAsync() function was added that encapsulates new FakeAsync().run(...).

New Features Relative to quiver

  • FakeAsync.elapsed returns the total amount of fake time elapsed since the FakeAsync instance was created.

  • new FakeAsync() now takes an initialTime argument that sets the default time for clocks created with FakeAsync.getClock(), and for the clock package's top-level clock variable.

New Features Relative to fake_async 0.1

  • FakeAsync.periodicTimerCount, FakeAsync.nonPeriodicTimerCount, and FakeAsync.microtaskCount provide visibility into the events scheduled within FakeAsync.run().

  • FakeAsync.getClock() provides access to fully-featured Clock objects based on FakeAsync's elapsed time.

  • FakeAsync.flushMicrotasks() empties the microtask queue without elapsing any time or running any timers.

  • FakeAsync.flushTimers() runs all microtasks and timers until there are no more scheduled.

0.1.2

  • Integrate with the clock package.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  fake_async: ^1.0.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:fake_async/fake_async.dart';
  
Version Uploaded Documentation Archive
1.0.1 Jul 13, 2018 Go to the documentation of fake_async 1.0.1 Download fake_async 1.0.1 archive
1.0.0 May 1, 2018 Go to the documentation of fake_async 1.0.0 Download fake_async 1.0.0 archive
0.1.2 Oct 7, 2014 Go to the documentation of fake_async 0.1.2 Download fake_async 0.1.2 archive
0.1.1 Sep 15, 2014 Go to the documentation of fake_async 0.1.1 Download fake_async 0.1.1 archive
0.1.0 Jul 21, 2014 Go to the documentation of fake_async 0.1.0 Download fake_async 0.1.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
52
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
74
Learn more about scoring.

We analyzed this package on Sep 18, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.3

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:fake_async/fake_async.dart.

Suggestions

Maintain an example.

Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use fake_async.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.36.0 <3.0.0
clock ^1.0.0 1.0.1
collection ^1.8.0 1.14.11
Transitive dependencies
meta 1.1.6
Dev dependencies
async >=1.10.0 <3.0.0
test ^0.12.28