fake_async
1.3.3, released 2 years ago by dart.dev
Fake asynchronous events like timers and microtasks for deterministic testing.
WASM-readyQuiet but busy
What it does
Provides a FakeAsync class that makes it easy to deterministically test code using asynchronous features like Futures, Streams, Timers, and microtasks. It lets you explicitly control the notion of current time and fires scheduled events immediately without real time elapsing.
AI-written summary of version 1.3.3, based on the package's README and metadata. Report an inaccuracy
Use it when
- You want to test code containing time-based asynchronous events deterministically.
- You need to avoid waiting for real time to pass during unit tests involving timeouts or delays.
Skip it when
- You are writing integration tests requiring real hardware or network I/O that cannot be mocked.
Strengths
- Allows explicit control over the current time in tests.
- Integrates seamlessly with the clock package for controlling DateTime.now() and Stopwatch.
Weaknesses
- Cannot control real hardware time or OS-level delays outside of Dart's asynchronous zone mechanisms.
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 2
fakeAsync((async) {
expect(Completer().future.timeout(Duration(seconds: 5)),
throwsA(isA<TimeoutException>()));
async.elapse(Duration(seconds: 5));
});Works with
Packages commonly used together with fake_async: ones it builds on, ones built on it, and its own family.
- clockfake_async depends on itA fakeable wrapper for dart:core clock APIs.
- built_valueSame familyImmutable value types with builders, enum classes and JSON serialization for Dart.
- asyncSame familyUtility classes and helpers that extend Dart's async library.
- hooksSame familyDart API for the JSON-based protocol for package build and link hooks.
- code_assetsSame familyProvides the hook protocol specification for bundling native code with Dart packages.
- testSame familyA full featured library for writing and running Dart tests across platforms.
- typed_dataSame familyUtility functions and classes for easier work with dart:typed_data lists.
- http_parserSame familyA platform-independent package for parsing and serializing HTTP formats.