Ste
Ste

Reputation: 419

How can I test that a AlertDialog appeared?

Hello I have a window with a button that should open an AlertDialog. How can I build a test that tells me that the alert opened?

var button = find.byKey(KEY_ADD_WALLET);
await tester.tap(button);

expect(... ??? ...)

Upvotes: 1

Views: 593

Answers (1)

Ste
Ste

Reputation: 419

I found the answer myself:

var button = find.byKey(KEY_ADD_WALLET);
await tester.tap(button);
await tester.pumpAndSettle();
expect(find.byType(Dialog), findsOneWidget);

The magic is calling tester.pumpAndSettle();

A more specific test could be:

expect(find.descendant(of: find.byType(Dialog), matching: find.text("Add public wallet")),findsOneWidget);

Upvotes: 2

Related Questions