fake_async 0.1.2

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 37

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.

0.1.2

Features:

  • Integrate with the clock package (#7)

1. Depend on it

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


dependencies:
  fake_async: "^0.1.2"

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub 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
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

Analysis

This feature is new.
We welcome feedback.
More details: scoring.

We analyzed this package, and provided a score, details, and suggestions below.

  • tool failures on Jan 17, 2018
  • Dart: 2.0.0-dev.15.0
  • pana: 0.9.1

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
39 / 100
Health:
Code health derived from static analysis. [more]
58 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
0 / 100
Overall score:
Weighted score of the above. [more]
37

Platforms

Detected platforms:

Error(s) prevent platform classification.

Suggestions

  • Fix lib/fake_async.dart.

    Strong-mode analysis of lib/fake_async.dart failed with the following error:

    line: 100 col: 9
    super call must be last in an initializer list (see https://goo.gl/EY6hDP): 'super._()'.

  • Fix platform conflicts.

    Make sure none of the libraries use mutually exclusive dependendencies.

  • Fix issues reported by dartanalyzer.

    dartanalyzer reported 1 error(s) and 0 warning(s).

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • 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
clock >=0.1.1 <0.2.0 0.1.2
Dev dependencies
unittest >=0.11.0+2 <0.12.0