Skip to content

Instantly share code, notes, and snippets.

@RemeJuan
Created March 31, 2021 04:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RemeJuan/bde3586378ec02935b10bc54623b2833 to your computer and use it in GitHub Desktop.
Save RemeJuan/bde3586378ec02935b10bc54623b2833 to your computer and use it in GitHub Desktop.
Unit Testing a Utility function that returns a Widget (Test)
testWidgets('cant', (tester) async {
when(mockUrlLauncherHelper.cl(any)).thenAnswer((_) async => false);
when(mockCoreCubit.state).thenReturn(fixtureCoreCubitLoaded);
// assert
const mockUrl = 'https://test.test';
Future<void> future(BuildContext context) async {
await Future.delayed(const Duration(seconds: 1));
return htmlContentUtils.launchURL(context, mockUrl);
}
final widget = providedLocalizedWidgetForTesting(
child: LayoutBuilder(
builder: (context, _) {
return FutureBuilder(
future: future(context),
builder: (ctx, snapshot) {
return const SizedBox.shrink();
},
);
},
),
);
await tester.pumpWidget(widget);
await tester.pumpAndSettle();
await tester.pump(const Duration(seconds: 1));
expect(find.byType(Flushbar), findsOneWidget);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment