Skip to content

Commit

Permalink
fix: re-add support for matching body to query string regex (#1006)
Browse files Browse the repository at this point in the history
  • Loading branch information
halkeye authored and gr2m committed Oct 23, 2017
1 parent f22dcc3 commit be7a075
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/match_body.js
Expand Up @@ -43,7 +43,11 @@ function matchBody(spec, body) {
}

if (spec instanceof RegExp) {
return body.match(spec);
if (typeof body === "string") {
return body.match(spec);
} else {
return qs.stringify(body).match(spec);
}
}

if (!isMultipart && typeof spec === "string") {
Expand Down
21 changes: 21 additions & 0 deletions tests/test_body_match.js
Expand Up @@ -5,6 +5,27 @@ var test = require('tap').test;
var mikealRequest = require('request');
var assert = require('assert');

test('match body is regex trying to match string', function (t) {

nock('http://encodingsareus.com')
.post('/', new RegExp("a.+"))
.reply(200);

mikealRequest({
url: 'http://encodingsareus.com/',
method: 'post',
json: {
auth: {
passwd: 'abc'
}
},
}, function(err, res) {
if (err) throw err;
assert.equal(res.statusCode, 200);
t.end();
});

});
test('match body with regex', function (t) {

nock('http://encodingsareus.com')
Expand Down

0 comments on commit be7a075

Please sign in to comment.