Skip to content

Commit

Permalink
Use Chai to perform object diffs based on the config
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertHerhold committed Mar 20, 2015
1 parent 818cbf8 commit 501a592
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions lib/chai-subset.js
Original file line number Diff line number Diff line change
@@ -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
);
});
};
Expand Down Expand Up @@ -44,4 +50,4 @@ function compare(expected, actual) {
}
return ao === eo;
});
}
}

0 comments on commit 501a592

Please sign in to comment.