platform/packages/mock_request/README.md

27 lines
1.2 KiB
Markdown
Raw Normal View History

2021-06-24 11:59:11 +00:00
# Mock HTTP Request
2022-01-04 12:03:52 +00:00
![Pub Version (including pre-releases)](https://img.shields.io/pub/v/angel3_mock_request?include_prereleases)
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
2021-05-15 06:01:47 +00:00
[![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion)
2022-01-04 12:03:52 +00:00
[![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/master/packages/mock_request/LICENSE)
2021-06-24 11:59:11 +00:00
**Forked from `mock_request` to support NNBD**
2023-05-21 00:53:53 +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.
2022-01-04 12:03:52 +00:00
This package was originally designed to make testing [Angel3](https://angel3-framework.web.app/) applications smoother, but works with any Dart-based server.
2021-06-24 11:59:11 +00:00
## Usage
```dart
var rq = MockHttpRequest('GET', Uri.parse('/foo'));
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!')));
```
2021-06-24 11:59:11 +00:00
More examples can be found in the included test cases.