angel_test 1.1.0+1

  • Example
  • Installing
  • Versions
  • 23


version 1.0.6 build status

Testing utility library for the Angel framework.


The TestClient class is a custom angel_client that sends mock requests to your server. This means that you will not have to bind your server to HTTP to run. Plus, it is an angel_client, and thus supports services and other goodies.

The TestClient also supports WebSockets. WebSockets cannot be mocked (yet!) within this library, so calling the websocket() function will also bind your server to HTTP, if it is not already listening.

The return value is a WebSockets client instance (from package:angel_websocket);

var ws = await client.websocket('/ws');

// To receive all blobs of data sent on the WebSocket:


Several Matchers are bundled with this package, and run on any package:http Response, not just those returned by Angel.

test('foo', () async {
    var res = await client.get('/foo');
    expect(res, allOf([
        isJson({'foo': 'bar'}),
        hasHeader('server'), // Assert header present
        hasHeader('server', 'angel'), // Assert header present with value
        hasHeader('foo', ['bar', 'baz']), // ... Or multiple values
        hasBody(), // Assert non-empty body
        hasBody('{"foo":"bar"}') // Assert specific body

test('error', () async {
    var res = await client.get('/error');
    expect(res, isAngelHttpException());
    expect(res, isAngelHttpException(statusCode: 404, message: ..., errors: [...])) // Optional

hasValidBody is one of the most powerful Matchers in this library, because it allows you to validate a JSON body against a validation schema.

Angel provides a comprehensive validation library that integrates tightly with the very matcher package that you already use for testing. :)

test('validate response', () async {
    var res = await client.get('/bar');
    expect(res, hasValidBody(new Validator({
        'foo': isBoolean,
        'bar': [isString, equals('baz')],
        'age*': [],
        'nested': someNestedValidator


  • Dart 2/strong mode fixes.
  • Pass a useZone flag to AngelHttp through TestServer.


import 'package:angel_framework/angel_framework.dart';
import 'package:angel_test/angel_test.dart';
import 'package:angel_validate/angel_validate.dart';
import 'package:angel_websocket/server.dart';
import 'package:dart2_constant/io.dart';
import 'package:test/test.dart';

main() {
  Angel app;
  TestClient client;

  setUp(() async {
    app = new Angel()
      ..get('/hello', 'Hello')
          () => throw new AngelHttpException.forbidden(message: 'Test')
            ..errors.addAll(['foo', 'bar']))
      ..get('/body', (ResponseContext res) {
          () => {
                'michael': 'jackson',
                'billie': {'jean': 'hee-hee', 'is_my_lover': false}
              })'/hello', (req, res) async {
        return {'bar': req.body['foo']};
      ..get('/gzip', (req, res) async {
          ..headers['content-encoding'] = 'gzip'
          new AnonymousService(
              index: ([params]) async => [
                    {'michael': 'jackson'}
              create: (data, [params]) async => {'foo': 'bar'}));

    var ws = new AngelWebSocket(app);
    await app.configure(ws.configureServer);
    app.all('/ws', ws.handleRequest);

    app.errorHandler = (e, req, res) => e.toJson();

    client = await connectTo(app);

  tearDown(() async {
    await client.close();
    app = null;

  group('matchers', () {
    group('isJson+hasStatus', () {
      test('get', () async {
        final response = await client.get('/hello');
        expect(response, isJson('Hello'));

      test('post', () async {
        final response = await'/hello', body: {'foo': 'baz'});
        expect(response, allOf(hasStatus(200), isJson({'bar': 'baz'})));

    test('isAngelHttpException', () async {
      var res = await client.get('/error');
      expect(res, isAngelHttpException());
              statusCode: 403, message: 'Test', errors: ['foo', 'bar']));

    test('hasBody', () async {
      var res = await client.get('/body');
      expect(res, hasBody());
      expect(res, hasBody('OK'));

    test('hasHeader', () async {
      var res = await client.get('/hello');
      expect(res, hasHeader('server'));
      expect(res, hasHeader('server', 'angel'));
      expect(res, hasHeader('server', ['angel']));

    test('hasValidBody+hasContentType', () async {
      var res = await client.get('/valid');
      expect(res, hasContentType('application/json'));
          hasValidBody(new Validator({
            'michael*': [isString, isNotEmpty, equals('jackson')],
            'billie': new Validator({
              'jean': [isString, isNotEmpty],
              'is_my_lover': [isBool, isFalse]

    test('gzip decode', () async {
      var res = await client.get('/gzip');
      expect(res, hasHeader('content-encoding', 'gzip'));
      expect(res, hasBody('Poop'));

    group('service', () {
      test('index', () async {
        var foo = client.service('foo');
        var result = await foo.index();
        expect(result, [
          {'michael': 'jackson'}

      test('index', () async {
        var foo = client.service('foo');
        var result = await foo.create({});
        expect(result, {'foo': 'bar'});

    test('websocket', () async {
      var ws = await client.websocket();
      var foo = ws.service('foo');
      var result = await foo.onCreated.first;
      expect(, equals({'foo': 'bar'}));

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  angel_test: ^1.1.0+1

2. Install it

You can install packages from the command line:

with pub:

$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:angel_test/angel_test.dart';
Version Uploaded Documentation Archive
1.1.0+1 Jul 9, 2018 Go to the documentation of angel_test 1.1.0+1 Download angel_test 1.1.0+1 archive
1.1.0 Dec 7, 2017 Go to the documentation of angel_test 1.1.0 Download angel_test 1.1.0 archive
1.0.6 Jun 3, 2017 Go to the documentation of angel_test 1.0.6 Download angel_test 1.0.6 archive
1.0.5+1 May 27, 2017 Go to the documentation of angel_test 1.0.5+1 Download angel_test 1.0.5+1 archive
1.0.5 Apr 25, 2017 Go to the documentation of angel_test 1.0.5 Download angel_test 1.0.5 archive
1.0.4 Mar 29, 2017 Go to the documentation of angel_test 1.0.4 Download angel_test 1.0.4 archive
1.0.3 Mar 29, 2017 Go to the documentation of angel_test 1.0.3 Download angel_test 1.0.3 archive
1.0.2 Mar 25, 2017 Go to the documentation of angel_test 1.0.2 Download angel_test 1.0.2 archive
1.0.1 Mar 25, 2017 Go to the documentation of angel_test 1.0.1 Download angel_test 1.0.1 archive
1.0.0 Jan 28, 2017 Go to the documentation of angel_test 1.0.0 Download angel_test 1.0.0 archive

All 19 versions...

Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Fix dependencies in pubspec.yaml.

Running pub upgrade failed with the following output:

ERR: The current Dart SDK version is 2.1.0.
 Because angel_test depends on angel_client >=1.0.0-dev+1 <2.0.0-alpha which requires SDK version <2.0.0, version solving failed.

Maintenance issues and suggestions

Fix platform conflicts. (-20 points)

Error(s) prevent platform classification:

Fix dependencies in pubspec.yaml.

Running dartdoc failed. (-10 points)

Make sure dartdoc runs without any issues.

The description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.8.9 <3.0.0