Skip to content

Instantly share code, notes, and snippets.

@easylive1989
Last active September 24, 2023 03:09
Show Gist options
  • Save easylive1989/e5e7b6a9986b572f6f67dbe4c60ff03b to your computer and use it in GitHub Desktop.
Save easylive1989/e5e7b6a9986b572f6f67dbe4c60ff03b to your computer and use it in GitHub Desktop.
2023鐵人賽_D10_2
import 'dart:async';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'scheduler_3_test.mocks.dart';
@GenerateNiceMocks([MockSpec<WalletRepository>()])
main() {
test("update wallet after 5 seconds", () async {
var mockWalletRepository = MockWalletRepository();
UpdateWalletScheduler(mockWalletRepository).start();
await Future.delayed(const Duration(seconds: 5));
verify(mockWalletRepository.update()).called(1);
});
}
class UpdateWalletScheduler {
final WalletRepository walletRepository;
UpdateWalletScheduler(this.walletRepository);
void start() {
Timer.periodic(const Duration(seconds: 5), (timer) {
walletRepository.update();
});
}
}
class WalletRepository {
Future<void> update() async {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment