testWidgets('Find transfer button', (tester) async {
await _createWidget(tester);
expect(find.byIcon(Icons.cached), findsOneWidget);
expect(find.text('Transfer'), findsOneWidget);
});
testWidgets('Find available balance section', (tester) async {
await _createWidget(tester);
final bank = BankModel();
expect(find.text('Available balance'), findsOneWidget);
expect(bank.available, 0);
});
testWidgets('Find spent section', (tester) async {
await _createWidget(tester);
final bank = BankModel();
expect(find.text('Spent'), findsOneWidget);
expect(bank.spent, 0);
});
Fora do escopo do main()eu criei uma função pra toda vez não ficar repetindo o mesmo código dentro de cada teste.
Future<void> _createWidget(WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(
home: BankInherited(
child: const Home(),
),
));
}