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 +}