From 501a59287348dd0968ad14b71c6e7aa232bfba1e Mon Sep 17 00:00:00 2001 From: RobertHerhold Date: Fri, 20 Mar 2015 19:03:45 -0400 Subject: [PATCH] Use Chai to perform object diffs based on the config --- lib/chai-subset.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/chai-subset.js b/lib/chai-subset.js index d2f7076..4fac938 100644 --- a/lib/chai-subset.js +++ b/lib/chai-subset.js @@ -1,14 +1,20 @@ var CircularJSON = require('circular-json'); -module.exports = function(chai) { - chai.Assertion.addChainableMethod('containSubset', function (expected) { - var actual = this.__flags.object; - var msg = "\n" + CircularJSON.stringify(actual, null, "\t") + "\n"; - this.assert( +module.exports = function(chai, utils) { + var Assertion = chai.Assertion; + var assertionPrototype = Assertion.prototype; + + Assertion.addChainableMethod('containSubset', function (expected) { + var actual = utils.flag(this, 'object'); + var showDiff = chai.config.showDiff; + + assertionPrototype.assert.call(this, compare(expected, actual), - 'expected' + msg + 'to contain subset \n#{exp}', - 'expected' + msg + 'not to contain subset \n#{exp}', - expected + 'expected #{act} to contain subset #{exp}', + 'expected #{act} to not contain subset #{exp}', + expected, + actual, + showDiff ); }); }; @@ -44,4 +50,4 @@ function compare(expected, actual) { } return ao === eo; }); -} \ No newline at end of file +}