manual_clock 1.0.0
manual_clock: ^1.0.0 copied to clipboard
A package for testing current time related code.
Manual Clock #
This package is for testing current time related code.
The ManualClock class is a derived class of Clock.
With clock and fake_async libraries, you can test current time (clock.now()) related code. But inside fake async callback, you can't use await. Because of this restriction, Sometimes it is hard to test your code. With this library, you can test current time related code using await.
Getting started #
pubspec.yaml
dev_dependencies:
manual_clock: ^1.0.0
Usage #
test('a test case', () async {
await withManualClock((clock) async {
final obj = ClassDependOnNow(...);
clock.elapse(Duration(...));
// You can use await inside callback
final result = await obj.getResult();
expect(result, ...);
},
// optionally set initial time
initialTime: DateTime(2000, 1, 1));
});