From e3e170d3e00b41f3fb87f775cf92725d5a8cfe01 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Sat, 29 Nov 2014 16:51:11 -0500 Subject: [PATCH 1/2] Fixes issue #291, adds assert.sameDeepMembers --- lib/chai/interface/assert.js | 19 +++++++++++++++++++ test/assert.js | 14 ++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/lib/chai/interface/assert.js b/lib/chai/interface/assert.js index 1b14c7a36..4f4e6ad2b 100644 --- a/lib/chai/interface/assert.js +++ b/lib/chai/interface/assert.js @@ -1052,6 +1052,25 @@ module.exports = function (chai, util) { new Assertion(set1, msg).to.have.same.members(set2); } + /** + * ### .sameDeepMembers(set1, set2, [message]) + * + * Asserts that `set1` and `set2` have deeply the same members. + * Order is not taken into account. + * + * assert.sameMembers([ {b: 3}, {a: 2}, {c: 5} ], [ {c: 5}, {b: 3}, {a: 2} ], 'same deep members'); + * + * @name sameDeepMembers + * @param {Array} set1 + * @param {Array} set2 + * @param {String} message + * @api public + */ + + assert.sameDeepMembers = function (set1, set2, msg) { + new Assertion(set1, msg).to.have.same.deep.members(set2); + } + /** * ### .includeMembers(superset, subset, [message]) * diff --git a/test/assert.js b/test/assert.js index 7a53cf9b7..008266c8a 100644 --- a/test/assert.js +++ b/test/assert.js @@ -673,6 +673,20 @@ describe('assert', function () { err(function() { assert.isBelow(1, 1); }, 'expected 1 to be below 1'); + + }); + + it('memberDeepEquals', function() { + assert.sameDeepMembers([ {b: 3}, {a: 2}, {c: 5} ], [ {c: 5}, {b: 3}, {a: 2} ], 'same deep members'); + assert.sameDeepMembers([ {b: 3}, {a: 2}, 5, "hello" ], [ "hello", 5, {b: 3}, {a: 2} ], 'same deep members'); + + err(function() { + assert.sameDeepMembers([ {b: 3} ], [ {c: 3} ]) + }, 'expected [ { b: 3 } ] to have the same members as [ { c: 3 } ]'); + + err(function() { + assert.sameDeepMembers([ {b: 3} ], [ {b: 5} ]) + }, 'expected [ { b: 3 } ] to have the same members as [ { b: 5 } ]'); }); }); From 0d814eb6f20209aa2af65c338c57d38a57944ae6 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Sun, 30 Nov 2014 09:34:33 -0500 Subject: [PATCH 2/2] Changed public comment of sameDeepMemebers to be more clear --- lib/chai/interface/assert.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/chai/interface/assert.js b/lib/chai/interface/assert.js index 4f4e6ad2b..717737a31 100644 --- a/lib/chai/interface/assert.js +++ b/lib/chai/interface/assert.js @@ -1055,10 +1055,10 @@ module.exports = function (chai, util) { /** * ### .sameDeepMembers(set1, set2, [message]) * - * Asserts that `set1` and `set2` have deeply the same members. + * Asserts that `set1` and `set2` have the same members - using a deep equality checking. * Order is not taken into account. * - * assert.sameMembers([ {b: 3}, {a: 2}, {c: 5} ], [ {c: 5}, {b: 3}, {a: 2} ], 'same deep members'); + * assert.sameDeepMembers([ {b: 3}, {a: 2}, {c: 5} ], [ {c: 5}, {b: 3}, {a: 2} ], 'same deep members'); * * @name sameDeepMembers * @param {Array} set1