2021-05-14 08:06:16 +00:00
|
|
|
# angel3_mock_request
|
2021-05-15 06:14:04 +00:00
|
|
|
[](https://pub.dartlang.org/packages/angel3_mock_request)
|
2021-05-14 08:06:16 +00:00
|
|
|
[](https://dart.dev/null-safety)
|
2021-05-15 06:01:47 +00:00
|
|
|
[](https://gitter.im/angel_dart/discussion)
|
2021-03-18 23:10:19 +00:00
|
|
|
|
2021-05-14 10:34:09 +00:00
|
|
|
[](https://github.com/dukefirehawk/angel/tree/angel3/packages/mock_request/LICENSE)
|
2021-03-18 23:10:19 +00:00
|
|
|
|
|
|
|
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 testing
|
2021-05-14 10:34:09 +00:00
|
|
|
[Angel](https://github.com/dukefirehawk/angel/tree/angel3)
|
2021-03-18 23:10:19 +00:00
|
|
|
applications smoother, but works with any Dart-based server. :)
|
|
|
|
|
|
|
|
# Usage
|
|
|
|
```dart
|
2021-05-14 08:06:16 +00:00
|
|
|
var rq = MockHttpRequest('GET', Uri.parse('/foo'));
|
2021-03-18 23:10:19 +00:00
|
|
|
await rq.close();
|
|
|
|
await 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 tests.
|