1
resposta

Testes pra mim não falham como no vídeo

Eu tentei até fazer um group com todos os testes desse arquivo, mas não falha de qualquer forma, mesmo teoricamente tendo chamado a mesma instância do mock.

void main() { final MockBankHttp httpMock = MockBankHttp(); group('Widget tests', () { testWidgets('My widget has a text "Spent" ', (tester) async { when(httpMock.dolarToReal()).thenAnswer((_) async => ('5')); await tester.pumpWidget(MaterialApp( home: BankInherited(child: Home(api: httpMock.dolarToReal())), )); final spentFinder = find.text('Spent'); expect(spentFinder, findsOneWidget); verify(httpMock.dolarToReal()).called(1); });

testWidgets("finds a LinearProgressIndicator", (tester) async {
  when(httpMock.dolarToReal()).thenAnswer((_) async => ('5'));
  await tester.pumpWidget(MaterialApp(
    home: BankInherited(child: Home(api: httpMock.dolarToReal())),
  ));

  expect(find.byType(LinearProgressIndicator), findsOneWidget);
  verify(httpMock.dolarToReal()).called(1);
});
testWidgets("finds an AccountStatus", (tester) async {
  when(httpMock.dolarToReal()).thenAnswer((_) async => ('5'));
  await tester.pumpWidget(MaterialApp(
    home: BankInherited(child: Home(api: httpMock.dolarToReal())),
  ));

  expect(find.byKey(const Key('testKey')), findsOneWidget);
  verify(httpMock.dolarToReal()).called(1);
});

testWidgets('finds 5 BoxCards', (tester) async {
  when(httpMock.dolarToReal()).thenAnswer((_) async => ('5'));
  await tester.pumpWidget(MaterialApp(
      home: BankInherited(child: Home(api: httpMock.dolarToReal()))));

  expect(find.byWidgetPredicate((widget) {
    if (widget is BoxCard) {
      return true;
    } else {
      return false;
    }
  }), findsNWidgets(5));
  verify(httpMock.dolarToReal()).called(1);
});

testWidgets('When deposit is tapped, it should raise earned to 10',
    (tester) async {
  when(httpMock.dolarToReal()).thenAnswer((_) async => ('5'));
  await tester.pumpWidget(MaterialApp(
    home: BankInherited(child: Home(api: httpMock.dolarToReal())),
  ));
  await tester.tap(find.text('Deposit'));
  await tester.tap(find.text('Earned'));
  await tester.pumpAndSettle();
  expect(find.text('\$10.0'), findsOneWidget);
  verify(httpMock.dolarToReal()).called(1);
});

testWidgets('Testing Mock Http dolarToReal', (tester) async {
  when(httpMock.dolarToReal()).thenAnswer((_) async => ('5'));
  await tester.pumpWidget(MaterialApp(
    home: BankInherited(child: Home(api: httpMock.dolarToReal())),
  ));
  verify(httpMock.dolarToReal()).called(1);
});

}); } aqui está toda a minha main, suponho que seja algo a ver com a versão do flutter? No momento estou usando a mais atual. Só queria confirmar se não tem nada de errado

1 resposta

Ola, tenta usar a mesma versão do curso