Skip to main content

angel3_mock_request 10.0.0 copy "angel3_mock_request: ^10.0.0" to clipboard
angel3_mock_request: ^10.0.0 copied to clipboard

Manufacture dart:io HttpRequests, HttpResponses, HttpHeaders, etc.

Mock HTTP Request #

Pub Version (including pre-releases) Null Safety Discord License

Forked from mock_request to support NNBD

Manufacture dart:io HttpRequests, HttpResponses, HttpHeaders, etc. This makes it possible to test server-side Dart applications without having to ever bind to a port.

This package was originally designed to make testing Angel3 applications smoother, but works with any Dart-based server.

Installation #

In your pubspec.yaml:

dev_dependencies:
  angel3_mock_request: ^10.0.0

Usage #

var rq = MockHttpRequest('GET', Uri.parse('/foo'));
await rq.close();
await AngelHttp(app).handleRequest(rq); // Run within your server-side application
var rs = rq.response;
expect(rs.statusCode, equals(200));
expect(await rs.transform(utf8.decoder).join(),
    equals(json.encode('Hello, world!')));

More examples can be found in the included test cases.

Migrating from 9.x to 10.0.0 #

The breaking changes of each release are listed in the CHANGELOG. Those of 10.0.0 that may need changes in an app:

  • Streams: MockHttpRequest extends Stream<Uint8List>, so its stream methods have the signatures of dart:io's HttpRequest; code that treated it as a Stream<List<int>> may need .cast<List<int>>().
  • Encoding: write throws an ArgumentError for a character its encoding cannot represent, instead of truncating it. Set the content-type charset, or encoding, to one that can represent it.
0
likes
160
points
1.41k
downloads

Documentation

API reference

Publisher

verified publisherdukefirehawk.com

Weekly Downloads

Manufacture dart:io HttpRequests, HttpResponses, HttpHeaders, etc.

Homepage
Repository (GitHub)
View/report issues
Contributing

License

BSD-3-Clause (license)

Dependencies

charcode

More

Packages that depend on angel3_mock_request