manual_clock 1.0.0 copy "manual_clock: ^1.0.0" to clipboard
manual_clock: ^1.0.0 copied to clipboard

A package for testing current time related code.

example/example.dart

import 'package:test/test.dart';
import 'package:clock/clock.dart';
import 'package:manual_clock/manual_clock.dart';

class ClassDependOnNow {
  final _startTime = clock.now();

  Duration get elapsed => clock.now().difference(_startTime);

  Future<Duration> someComplicatedTask() async {
    await Future.delayed(const Duration(seconds: 1));
    return elapsed;
  }
}

void main() {
  test('a test case', () async {
    await withManualClock((clock) async {
      final stopwatch = ClassDependOnNow();
      expect(stopwatch.elapsed, Duration.zero);

      final duration = Duration(minutes: 3);
      clock.elapse(duration);
      expect(stopwatch.elapsed, duration);

      final result = await stopwatch.someComplicatedTask();
      expect(result, duration);
    });
  });
}
1
likes
0
points
37
downloads

Publisher

verified publishersousyokunotomonokai.com

Weekly Downloads

A package for testing current time related code.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

clock

More

Packages that depend on manual_clock