Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle arrays like objects in match_body #719

Merged
merged 1 commit into from
Oct 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/match_body.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function deepEqualExtended(spec, body) {
if (spec && spec.constructor === RegExp) {
return spec.test(body);
}
if (spec && spec.constructor === Object && body) {
if (spec && spec.constructor === Object || spec.constructor === Array && body) {
var keys = Object.keys(spec);
for (var i = 0; i < keys.length; i++) {
if (!deepEqualExtended(spec[keys[i]], body[keys[i]])) {
Expand Down
21 changes: 21 additions & 0 deletions tests/test_body_match.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,24 @@ test('match body with regex', function (t) {
});

});

test('match body with regex inside array', function (t) {

nock('http://encodingsareus.com')
.post('/', {items: [{name: /t.+/}]})
.reply(200);

mikealRequest({
url: 'http://encodingsareus.com/',
method: 'post',
json: {
items: [{
name: 'test'
}]
},
}, function(err, res) {
if (err) throw err;
assert.equal(res.statusCode, 200);
t.end();
});
})