unexpected-messy
Advanced tools
Comparing version 2.7.2 to 2.7.3
@@ -204,2 +204,6 @@ var messy = require('messy'), | ||
function expectMessageToSatisfy(expect, subject, value) { | ||
if (typeof value === 'string' || typeof Buffer !== 'undefined' && Buffer.isBuffer(value)) { | ||
value = new messy.Message(value); | ||
} | ||
var upgradedOrDowngradedMessageBodyAndSpecBody = upgradeOrDowngradeMessageBodyToMatchSpecBody(subject, value), | ||
@@ -209,3 +213,3 @@ subjectBody = upgradedOrDowngradedMessageBodyAndSpecBody.messageBody, | ||
if (value && typeof value === 'object') { | ||
if (value && typeof value === 'object' && !value.isMessyMessage) { | ||
var unsupportedKeys = Object.keys(value).filter(function (key) { | ||
@@ -229,16 +233,16 @@ return key !== 'body' && key !== 'fileName' && key !== 'decodedBody' && key !== 'text' && key !== 'headers' && key !== 'parts'; | ||
this.errorMode = 'default'; | ||
} | ||
if (typeof value.parts !== 'undefined') { | ||
expect(subject, 'to be a multipart message'); | ||
expect(subject.parts, 'to be an array'); | ||
if (typeof value.parts === 'function') { | ||
expect(subject.parts, 'to satisfy', value.parts); | ||
} else if (Array.isArray(value.parts)) { | ||
this.errorMode = 'bubble'; | ||
expect(subject, 'to have number of parts', value.parts.length); | ||
} else if (value.parts && typeof value.parts === 'object') { | ||
expect(value.parts, 'to be an object whose keys satisfy', /^\d+/); | ||
if (typeof value.parts !== 'undefined') { | ||
expect(subject, 'to be a multipart message'); | ||
expect(subject.parts, 'to be an array'); | ||
if (typeof value.parts === 'function') { | ||
expect(subject.parts, 'to satisfy', value.parts); | ||
} else if (Array.isArray(value.parts)) { | ||
this.errorMode = 'bubble'; | ||
expect(subject, 'to have number of parts', value.parts.length); | ||
} else if (value.parts && typeof value.parts === 'object') { | ||
expect(value.parts, 'to be an object whose keys satisfy', /^\d+/); | ||
} | ||
this.errorMode = 'default'; | ||
} | ||
this.errorMode = 'default'; | ||
} | ||
@@ -249,5 +253,2 @@ | ||
try { | ||
if (typeof value === 'string') { | ||
value = new messy.Message(value); | ||
} | ||
expect(subject.headers, 'to [exhaustively] satisfy', value.headers || {}); | ||
@@ -263,3 +264,3 @@ | ||
} | ||
if (typeof value.parts !== 'undefined' && typeof value.parts !== 'function') { | ||
if (!value.isMessyMessage && typeof value.parts !== 'undefined' && typeof value.parts !== 'function') { | ||
if (Array.isArray(value.parts)) { | ||
@@ -266,0 +267,0 @@ expect(subject.parts, 'to satisfy', value.parts); |
{ | ||
"name": "unexpected-messy", | ||
"version": "2.7.2", | ||
"version": "2.7.3", | ||
"description": "Unexpected plugin for the messy library", | ||
@@ -5,0 +5,0 @@ "main": "lib/unexpectedMessy.js", |
Unexpected-messy | ||
================ | ||
Plugin for [Unexpected](https://github.com/sunesimonsen/unexpected) that adds the ability to inspect and match instances of the HttpRequest and HttpResponse classes from the [Messy library](https://github.com/papandreou/messy). | ||
Plugin for [Unexpected](https://github.com/sunesimonsen/unexpected) that adds the ability to inspect and match instances of the HttpRequest, HttpResponse, HttpExchange, HttpConversation, Mail, and Message classes from the [Messy library](https://github.com/papandreou/messy). It's originally built for [unexpected-express](https://github.com/papandreou/unexpected-express) and [unexpected-http](https://github.com/papandreou/unexpected-http), but can also be used standalone. | ||
It's originally built for [unexpected-express](https://github.com/papandreou/unexpected-express), 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: | ||
Right now it depends on some unreleased features that are due to land in unexpected 5, so stay tuned. | ||
```js | ||
var messy = require('messy'), | ||
expect = require('unexpected').clone().installPlugin(require('unexpected-messy')); | ||
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)}}); | ||
``` | ||
![Diff output](diffOutput.png) | ||
[![NPM version](https://badge.fury.io/js/unexpected-messy.png)](http://badge.fury.io/js/unexpected-messy) | ||
@@ -11,0 +23,0 @@ [![Build Status](https://travis-ci.org/papandreou/unexpected-messy.png?branch=master)](https://travis-ci.org/papandreou/unexpected-messy) |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
180417
12
2737
32