commit | b49aa83d27797093e628c7a304d235e7b8ab25e6 | [log] [tgz] |
---|---|---|
author | Kevin Moore <kevmoo@users.noreply.github.com> | Sun Jul 15 19:08:04 2018 -0700 |
committer | GitHub <noreply@github.com> | Sun Jul 15 19:08:04 2018 -0700 |
tree | 90656a91d7e947e562a1b4dc93374c536a279862 | |
parent | b703d0c4fed4c57ac4d2c0637b2b34474d22e14a [diff] |
Fix travis (#7)
This package provides a Clock
class which encapsulates the notion of the “current time” and provides easy access to points relative to the current time. Different Clock
s can have a different notion of the current time, and the default top-level clock
's notion can be swapped out to reliably test timing-dependent code.
For example, you can use clock
in your libraries like this:
// run_with_timing.dart import 'package:clock/clock.dart'; /// Runs [callback] and prints how long it took. T runWithTiming<T>(T callback()) { var stopwatch = clock.stopwatch()..start(); var result = callback(); print("It took ${stopwatch.elapsed}!"); return result; }
...and then test your code using the fake_async
package, which automatically overrides the current clock:
// run_with_timing_test.dart import 'run_with_timing.dart'; import 'package:fake_async/fake_async.dart'; import 'package:test/test.dart'; void main() { test("runWithTiming() prints the elapsed time", () { new FakeAsync().run((async) { expect(() { runWithTiming(() { async.elapse(new Duration(seconds: 10)); }); }, prints("It took 0:00:10.000000!")); }); }); }