Created
September 24, 2023 03:09
-
-
Save easylive1989/ba7f1503e2b6e0223ab229ee19ef4398 to your computer and use it in GitHub Desktop.
2023鐵人賽_D10_3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
import 'package:fake_async/fake_async.dart'; | |
import 'package:flutter_test/flutter_test.dart'; | |
import 'package:mockito/annotations.dart'; | |
import 'package:mockito/mockito.dart'; | |
import 'scheduler_2_test.mocks.dart'; | |
@GenerateNiceMocks([MockSpec<WalletRepository>()]) | |
main() { | |
test("update wallet after 5 seconds", () async { | |
fakeAsync((async) { | |
var mockWalletRepository = MockWalletRepository(); | |
UpdateWalletScheduler(mockWalletRepository).start(); | |
async.elapse(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