http_test_client 0.0.1 copy "http_test_client: ^0.0.1" to clipboard
http_test_client: ^0.0.1 copied to clipboard

Dart 1 only

A package for testing http clients on flutter or the Dart vm.

http_test_client #

A package for testing http clients on flutter or the Dart vm.

Example #

The following example forces all HTTP requests to return a successful empty response in a test enviornment. No actual HTTP requests will be performed.

class MyHttpOverrides extends HttpOverrides {
  HttpClient() createClient(_) {
    return new HttpTestClient((request, client) {
        // the default response is an empty 200.
        return new HttpTestResponse();
    });
  }
}

void main() {
  // overrides all HttpClients.
  HttpOverrides.global = new MyHttpOverrides();

  group('HttpClient', () {
    test('returns OK', () async {
      // this is actually an instance of [HttpTestClient].
      final client = new HttpClient();
      final request = client.getUrl(new Uri.https('google.com'));
      final response = await request.close();

      expect(response.statusCode, HttpStatus.OK);
    });
  });
}
0
likes
25
pub points
6%
popularity

Publisher

unverified uploader

A package for testing http clients on flutter or the Dart vm.

Repository (GitHub)
View/report issues

License

BSD-3-Clause (LICENSE)

More

Packages that depend on http_test_client