You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In recent versions of the flutter_svg package, using the mockNetworkImages method results in the following error:
The following _TypeError was thrown running a test (but after the test had completed):
type 'Null' is not a subtype of type 'Future<HttpClientRequest>'
This issue occurs when attempting to mock network images using mockNetworkImages in widget tests that include SVG images.
To Reproduce
Steps to reproduce the behavior:
Add flutter_svg package;
Create a widget that displays an SVG image from network using SvgPicture.network;
Use the mockNetworkImages utility method to mock the network image in a widget test;
import'package:flutter/material.dart';
import'package:flutter_svg/flutter_svg.dart';
import'package:flutter_test/flutter_test.dart';
import'package:mocktail_image_network/mocktail_image_network.dart';
classFakeAppextendsStatelessWidget {
constFakeApp({super.key});
@overrideWidgetbuild(BuildContext context) {
returnMaterialApp(
home:Scaffold(
body:Center(
child:SvgPicture.network(
// URL to the Flutter logo from https://flutter.dev/brand'https://storage.googleapis.com/cms-storage-bucket/847ae81f5430402216fd.svg',
),
),
),
);
}
}
voidmain() {
testWidgets('can use mocktail for network images', (tester) async {
awaitmockNetworkImages(() async=> tester.pumpWidget(constFakeApp()));
expect(find.byType(SvgPicture), findsOneWidget);
});
}
Expected behavior
The widget test should successfully mock the SVG image without any type errors, allowing for proper rendering and testing of the widget.
Logs
00:02 +0: can use mocktail for network images
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following _TypeError was thrown running a test:
type 'Null' is not a subtype of type 'Future<HttpClientRequest>'
When the exception was thrown, this was the stack:
#0 _MockHttpClient.openUrl (package:mocktail_image_network/src/mocktail_image_network.dart:52:7)
#1 IOClient.send (package:http/src/io_client.dart:88:38)
#2 BaseClient._sendUnstreamed (package:http/src/base_client.dart:93:38)
...
#882 WidgetTester.pumpWidget (package:flutter_test/src/widget_tester.dart:591:27)
#883 main.<anonymous closure>.<anonymous closure> (file:///.../mocktail/packages/mocktail_image_network/example/test/image_test.dart:8:48)
#888 HttpOverrides.runZoned (dart:_http/overrides.dart:55:23)
#889 mockNetworkImages (package:mocktail_image_network/src/mocktail_image_network.dart:44:24)
#890 main.<anonymous closure> (file:///.../mocktail/packages/mocktail_image_network/example/test/image_test.dart:8:11)
#891 testWidgets.<anonymous closure>.<anonymous closure> (package:flutter_test/src/widget_tester.dart:183:29)
<asynchronous suspension>
#892 TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:1017:5)
<asynchronous suspension>
<asynchronous suspension>
(elided 9 frames from dart:async and package:stack_trace)
The test description was:
can use mocktail for network images
════════════════════════════════════════════════════════════════════════════════════════════════════
00:02 +0 -1: can use mocktail for network images [E]
Test failed. See exception logs above.
The test description was: can use mocktail for network images
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following _TypeError was thrown running a test (but after the test had completed):
type 'Null' is not a subtype of type 'Future<HttpClientRequest>'
When the exception was thrown, this was the stack:
#0 _MockHttpClient.openUrl (package:mocktail_image_network/src/mocktail_image_network.dart:52:7)
#1 IOClient.send (package:http/src/io_client.dart:88:38)
#2 BaseClient._sendUnstreamed (package:http/src/base_client.dart:93:38)
...
#882 WidgetTester.pumpWidget (package:flutter_test/src/widget_tester.dart:591:27)
#883 main.<anonymous closure>.<anonymous closure> (file:///.../mocktail/packages/mocktail_image_network/example/test/image_test.dart:8:48)
#888 HttpOverrides.runZoned (dart:_http/overrides.dart:55:23)
#889 mockNetworkImages (package:mocktail_image_network/src/mocktail_image_network.dart:44:24)
#890 main.<anonymous closure> (file:///.../mocktail/packages/mocktail_image_network/example/test/image_test.dart:8:11)
#891 testWidgets.<anonymous closure>.<anonymous closure> (package:flutter_test/src/widget_tester.dart:183:29)
<asynchronous suspension>
#892 TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:1017:5)
<asynchronous suspension>
<asynchronous suspension>
(elided 9 frames from dart:async and package:stack_trace)
════════════════════════════════════════════════════════════════════════════════════════════════════
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following _TypeError was thrown running a test (but after the test had completed):
type 'Null' is not a subtype of type 'Future<HttpClientRequest>'
When the exception was thrown, this was the stack:
#0 _MockHttpClient.openUrl (package:mocktail_image_network/src/mocktail_image_network.dart:52:7)
#1 IOClient.send (package:http/src/io_client.dart:88:38)
#2 BaseClient._sendUnstreamed (package:http/src/base_client.dart:93:38)
...
#882 WidgetTester.pumpWidget (package:flutter_test/src/widget_tester.dart:591:27)
#883 main.<anonymous closure>.<anonymous closure> (file:///.../mocktail/packages/mocktail_image_network/example/test/image_test.dart:8:48)
#888 HttpOverrides.runZoned (dart:_http/overrides.dart:55:23)
#889 mockNetworkImages (package:mocktail_image_network/src/mocktail_image_network.dart:44:24)
#890 main.<anonymous closure> (file:///.../mocktail/packages/mocktail_image_network/example/test/image_test.dart:8:11)
#891 testWidgets.<anonymous closure>.<anonymous closure> (package:flutter_test/src/widget_tester.dart:183:29)
<asynchronous suspension>
#892 TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:1017:5)
<asynchronous suspension>
<asynchronous suspension>
(elided 9 frames from dart:async and package:stack_trace)
════════════════════════════════════════════════════════════════════════════════════════════════════
To run this test again: dart test test/image_test.dart -p vm --plain-name 'can use mocktail for network images'
00:02 +0 -1: Some tests failed.
Describe the bug
In recent versions of the flutter_svg package, using the
mockNetworkImages
method results in the following error:This issue occurs when attempting to mock network images using
mockNetworkImages
in widget tests that include SVG images.To Reproduce
Steps to reproduce the behavior:
flutter_svg
package;SvgPicture.network
;mockNetworkImages
utility method to mock the network image in a widget test;Example Code
Expected behavior
The widget test should successfully mock the SVG image without any type errors, allowing for proper rendering and testing of the widget.
Logs
Additional context
Flutter SVG version: 2.0.10+1
Flutter version:
The text was updated successfully, but these errors were encountered: