-
Notifications
You must be signed in to change notification settings - Fork 26.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Have 404s from the fake HttpClient explain that tests don't hit the network but fake a 404 #13433
Comments
What happens when you run import 'package:http/http.dart' as http;
main() async {
var resp = await new http.Client().get('https://pbs.twimg.com/profile_images/760249570085314560/yCrkrbl3.jpg');
print(resp.bodyBytes);
} |
Also, could you try running the same code with plain |
The code prints out the response bytes, and then reports that no tests ran:
Running |
Probably this (i.e. by default we don't support loading images from the network in the test environment). You could overwrite |
However, keep in mind that |
I'd rather not do that if possible. This is only an issue because a recent change made it an exception for the image to not load: I think this may break any test on a widget tree that contains a NetworkImage. Because of that, I think the best approaches are either for NetworkImage to skip the responseCode check in tests or to revert that exception throwing entirely. |
OIC. /cc @amirh |
There's an example here, of how we override the http client in one of the Flutter tests so that it always returns an empty image: Regarding not throwing for network image loading errors - I think it makes sense to propagate the failure and allow developers to handle it. |
They're not technically exceptions, just errors that get reported to the error reporting mechanism, which the test framework interprets as a failure. If you're ok with a 404, you can use If you want to test with very specific images, you can do what @amirh mentions in his last comment. |
For now, we faked the image client similarly to the framework code @amirh linked above does: https://github.com/flutter/flutter_markdown/pull/17 Request: To reduce friction for other users who run into this, would it be possible to add a line to the output of the test failure explaining that the http client is faked to always return 404s in Flutter tests? |
Yeah, that makes a lot of sense. |
Removing tool designation since this does not depend on the tool at all |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
Steps to Reproduce
I'm loading a NetworkImage in a Flutter test, and it's failing with a 404 error. I've tried a number of different images that I can access from my browser, but the test is unable to load them.
Diff from flutter_markdown/master: https://github.com/flutter/flutter_markdown/compare/master...DaveShuckerow:image-fix
Any clue what might cause the error?
Logs
Flutter Doctor
The text was updated successfully, but these errors were encountered: