Skip to content

Commit

Permalink
Solves #920
Browse files Browse the repository at this point in the history
  • Loading branch information
edorivai committed May 28, 2017
1 parent 17d7c25 commit a109522
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/match_body.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ function deepEqualExtended(spec, body) {
}
if (spec && (spec.constructor === Object || spec.constructor === Array) && body) {
var keys = Object.keys(spec);
var bodyKeys = Object.keys(body);
if (keys.length !== bodyKeys.length) {
return false;
}
for (var i = 0; i < keys.length; i++) {
if (!deepEqualExtended(spec[keys[i]], body[keys[i]])) {
return false;
Expand Down
18 changes: 18 additions & 0 deletions tests/test_body_match.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,24 @@ test('match body with empty object inside', function (t) {
});
})

test('doesn\'t match body with mismatching keys', function (t) {
nock('http://encodingsareus.com')
.post('/', { a: 'a' })
.reply(200);

mikealRequest({
url: 'http://encodingsareus.com/',
method: 'post',
json: {
a: 'a',
b: 'b'
}
}, function(err) {
assert.ok(err);
t.end();
});
});

test('match body with form multipart', function(t) {

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

0 comments on commit a109522

Please sign in to comment.