1
resposta

The following MissingStubError was thrown running a test: 'save'

Para quem tiver seguido a solução que postei na aula anterior e estiver recebendo esse erro. Detalhes aqui: https://cursos.alura.com.br/forum/topico-type-null-is-not-a-subtype-of-type-future-list-contact-170695

══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following MissingStubError was thrown running a test:
'save'
No stub was found which matches the arguments of this method call:
save(Contact{id: 0, name: Alex, accountNumber: 1001})

Add a stub for this method using Mockito's 'when' API, or generate the mock for MockContactDao with
'returnNullOnMissingStub: true'.

Este é o código para mockar o método save do ContactDao. Basta inserir uma funcção when() necessária:

@GenerateMocks([ContactDao])
void main() {
  testWidgets('Should save a contact', (tester) async {
    final mockContactDao = MockContactDao();

    when(mockContactDao.findAll()).thenAnswer((_) async => []);
    when(mockContactDao.save(any)).thenAnswer((_) async => 1);
    await tester.pumpWidget(ByteBankApp(contactDao: mockContactDao));

    // Resto do teste //

  }
}    
1 resposta

Perfeito Fábio!

Mandou bem, continue assim!