Skip to content

Instantly share code, notes, and snippets.

@abhaysood
Created October 4, 2021 02:57
Show Gist options
  • Save abhaysood/50f1cb296994ba66fdfd3a022325b2a9 to your computer and use it in GitHub Desktop.
Save abhaysood/50f1cb296994ba66fdfd3a022325b2a9 to your computer and use it in GitHub Desktop.
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