Mocking Dart HTTP Client When Testing Flutter Widgets

If you’re not familiar with HTTP and Flutter widget tests, testWidgets() mocks the Dart http.Client to always return an HTTP 400 status! Surprising, I know. The idea is that you shouldn’t make real HTTP calls from your widget tests. But I think 99.9% of the time, this is not the response you want. Typically, you could mock the HTTP client with MockClient. This will work if you can provide an HttpClient directly to your widget. [Read More]