The Protevus Platform: Unified Full-Stack Development https://protevus.com
Find a file
2018-08-28 10:24:44 -04:00
.dart_tool/pub/bin Bump to 2.0.0-alpha 2018-08-28 10:24:44 -04:00
.idea Dart 2 fixes 2018-07-09 12:10:25 -04:00
example Bump to 2.0.0-alpha 2018-08-28 10:24:44 -04:00
lib Ensure Dart 1 compat 2018-07-09 12:21:14 -04:00
test Bump to 2.0.0-alpha 2018-08-28 10:24:44 -04:00
.gitignore Need to work on custom matchers 2016-12-10 12:05:31 -05:00
.travis.yml Dart 2 fixes 2018-07-09 12:10:25 -04:00
analysis_options.yaml Dart 2 fixes 2018-07-09 12:10:25 -04:00
CHANGELOG.md Bump to 2.0.0-alpha 2018-08-28 10:24:44 -04:00
LICENSE Initial commit 2016-10-16 16:01:59 -04:00
pubspec.yaml Bump to 2.0.0-alpha 2018-08-28 10:24:44 -04:00
README.md 1.0.6 2017-06-03 13:59:55 -04:00

angel_test

version 1.0.6 build status

Testing utility library for the Angel framework.

TestClient

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');
ws.service('api/users').onCreated.listen(...);

// To receive all blobs of data sent on the WebSocket:
ws.onData.listen(...);

Matchers

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'}),
        hasStatus(200),
        hasContentType(ContentType.JSON),
        hasContentType('application/json'),
        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. :)

https://github.com/angel-dart/validate

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