Skip to content

Commit

Permalink
Implement flag: with http mocked out with extra info
Browse files Browse the repository at this point in the history
  • Loading branch information
papandreou committed May 17, 2016
1 parent bc2e5ac commit 91d85e4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/unexpectedMitm.js
Expand Up @@ -606,7 +606,7 @@ module.exports = {
return recordedExchanges;
});
})
.addAssertion('<any> with http mocked out <array|object> <assertion>', function (expect, subject, requestDescriptions) { // ...
.addAssertion('<any> with http mocked out [with extra info] <array|object> <assertion>', function (expect, subject, requestDescriptions) { // ...
expect.errorMode = 'nested';
var mitm = createMitm();

Expand Down Expand Up @@ -819,7 +819,11 @@ module.exports = {
}).spread(function (httpConversation, httpConversationSatisfySpec, fulfilmentValue) {
expect.errorMode = 'default';
return expect(httpConversation, 'to satisfy', httpConversationSatisfySpec).then(function () {
return fulfilmentValue;
if (expect.flags['with extra info']) {
return [httpConversation, httpConversationSatisfySpec, fulfilmentValue];
} else {
return fulfilmentValue;
}
});
}).finally(function () {
mitm.disable();
Expand Down
18 changes: 18 additions & 0 deletions test/unexpectedMitm.js
Expand Up @@ -4,6 +4,7 @@ var pathModule = require('path'),
fs = require('fs'),
http = require('http'),
https = require('https'),
messy = require('messy'),
pem = require('pem'),
stream = require('stream'),
semver = require('semver'),
Expand Down Expand Up @@ -1381,6 +1382,23 @@ describe('unexpectedMitm', function () {
});
});

describe('with the "with extra info" flag', function () {
it('should resolve with the compared exchanges', function () {
return expect(
expect('GET /', 'with http mocked out with extra info', {
request: 'GET /',
response: 200
}, 'to yield response', 200),
'when fulfilled',
'to satisfy', [
new messy.HttpExchange(),
expect.it('to be an object'),
expect.it('to be an object')
]
);
});
});

it('should preserve the fulfilment value of the promise returned by the assertion being delegated to', function () {
return expect([1, 2], 'with http mocked out', [], 'when passed as parameters to', Math.max).then(function (value) {
expect(value, 'to equal', 2);
Expand Down

0 comments on commit 91d85e4

Please sign in to comment.