Unit Testing a Utility function that returns a Widget (Test)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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