Unexpected-messy
Plugin for Unexpected that adds the ability to inspect and match instances of the HttpRequest, HttpResponse, HttpExchange, HttpConversation, Mail, and Message classes from the Messy library. It's originally built for unexpected-express, unexpected-mitm and unexpected-http, but can also be used standalone.
In particular, it adds support for the to satisfy
assertion so that you can express your assertions using a very compact and precise syntax. When the conditions are not met, you get a full diff that includes the entire object as a single unit:
var messy = require('messy');
var expect = require('unexpected').clone().installPlugin(require('./lib/unexpectedMessy'));
expect(new messy.HttpResponse(
'HTTP/1.1 200 OK\r\n' +
'Content-Type: application/json\r\n' +
'\r\n' +
'{"foo":"bar","baz":456}'
), 'to satisfy', {statusCode: 404, body: {baz: expect.it('to be greater than', 1024)}});
expected
HTTP/1.1 200 OK
Content-Type: application/json
{ foo: 'bar', baz: 456 }
to satisfy { statusCode: 404, body: { baz:
} }
expect.it('to be greater than', 1024)
HTTP/1.1 200 OK
//
//
//
//
should be 404 Not Found
HTTP/1.1 200 OK
HTTP/1.1 404 Not Found
Content-Type: application/json
{
foo: 'bar',
baz:
456
//
should be greater than 1024
}