> For the complete documentation index, see [llms.txt](https://angel3-docs.dukefirehawk.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://angel3-docs.dukefirehawk.com/under-the-hood/testing.md).

# Testing

* [Testing](#testing)
  * [`connectTo(...)`](#connectto)
  * [`isJson(..)`](#isjson)
  * [`hasStatus(...)`](#hasstatus)
  * [More Matchers...](#more-matchers)
* [Next Up...](#next-up)

## Testing

Dart already has fantastic testing support, through a library of [testing helpers](https://github.com/dart-backend/angel/tree/master/packages/test) that will make test writing faster. The following functions are exported by [`package:angel3_test`](https://github.com/dart-backend/angel/tree/master/packages/test), and will make your testing much easier.

### connectTo

[Full definition](https://pub.dev/documentation/angel3_test/latest/angel3_test/connectTo.html)

This function will start `app` on an available port, and return a `TestClient` instance (based on [`package:angel3_client`](https://github.com/dart-backend/angel/tree/master/packages/client)) configured to send requests to the server. The client also supports session manipulation.

```dart
void main() {
  late TestClient client;

  setUp(() async {
    var app = Angel()..get('/hello', (req, res) => {'hello': 'world'});
    client = await connectTo(app);
  });

  // Shut down server, and cancel pending requests
  tearDown(() => client.close());

  test('hello', () async {
    // This returns an http.Response. :)
    var response = await client.get(Uri.parse('/hello'));
    expect(response, allOf(hasStatus(200), isJson({'hello': 'world'})));
  });
}
```

### isJson

A `Matcher` that asserts that the given `http.Response` equals `value` when decoded as JSON. This uses `test.equals` internally, so anything that would pass that matcher passes this one.

### hasStatus

A `Matcher` that asserts the given `http.Response` has the given `status` code.

### More Matchers

The complete set of `angel3_test` Matchers can be found [here](https://pub.dev/documentation/angel3_test/latest/angel3_test/angel3_test-library.html).

## Next Up

1. Find out how to [handle errors](https://angel3-docs.dukefirehawk.com/under-the-hood/error-handling.md) in an Angel3 application.
2. Learn how to use the handy [Angel3 CLI](https://angel3-docs.dukefirehawk.com/command-line-interface/cli-setup.md).
