Skip to content

Instantly share code, notes, and snippets.

@abhaysood
Created Oct 4, 2021
Embed
What would you like to do?
semantic_announcement_tester sample tests
testWidgets('One announcement', (WidgetTester tester) async {
final mock = MockSemanticAnnouncements(tester);
const expectedAnnouncement = AnnounceSemanticsEvent(
"Announcement made",
TextDirection.ltr,
);
await tester.pumpWidget(const MyApp());
// Tap to trigger an announcement
await tester.tap(find.byType(ElevatedButton));
expect(
mock.announcements,
hasOneAnnouncement(expectedAnnouncement),
);
});
testWidgets('N announcements', (WidgetTester tester) async {
final mock = MockSemanticAnnouncements(tester);
const expectedAnnouncement = AnnounceSemanticsEvent(
"Announcement made",
TextDirection.ltr,
);
await tester.pumpWidget(const MyApp());
// Tap twice to trigger two announcements
await tester.tap(find.byType(ElevatedButton));
await tester.tap(find.byType(ElevatedButton));
expect(
mock.announcements,
hasNAnnouncements([
expectedAnnouncement, expectedAnnouncement
]),
);
});
testWidgets("Zero announcements", (WidgetTester tester) async {
final mock = MockSemanticAnnouncements(tester);
await tester.pumpWidget(const MyApp());
expect(mock.announcements, hasZeroAnnouncements());
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment