provideMockedNetworkImages<T> function
Provides a mock HTTP client that responds with a fake image for all requests. Wrap your test body with this function, for example:
testWidgets('should do something', (tester) async {
provideMockedNetworkImages(
() async {
await tester.pumpWidget(
MaterialApp(
home: MyWidget(),
),
);
...
},
);
});
See the README for more information.
Implementation
T provideMockedNetworkImages<T>(
T Function() callback, {
/// Provide custom image bytes for the HTTP responses
List<int> imageBytes = fakeImageBytes,
}) {
return HttpOverrides.runZoned(
callback,
createHttpClient: (_) => _createMockImageHttpClient(
_,
imageBytes,
),
);
}