Skip to content

Commit

Permalink
Merge e07e57f into f82f43f
Browse files Browse the repository at this point in the history
  • Loading branch information
romario333 committed Nov 25, 2013
2 parents f82f43f + e07e57f commit 7ee5be9
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
15 changes: 15 additions & 0 deletions lib/chai/assertion.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@ module.exports = function (_chai, util) {

Assertion.showDiff = true;

/*!
* ### Assertion.truncateThreshold
*
* User configurable property, sets length threshold for actual and
* expected values in assertion errors. If this threshold is exceeded,
* the value is truncated.
*
* Set it to zero if you want to disable truncating altogether.
*
* Assertion.truncateThreshold = 0; // disable truncating
*
* @api public
*/
Assertion.truncateThreshold = 40;

Assertion.addProperty = function (name, fn) {
util.addProperty(this.prototype, name, fn);
};
Expand Down
2 changes: 1 addition & 1 deletion lib/chai/utils/objDisplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = function (obj) {
var str = inspect(obj)
, type = Object.prototype.toString.call(obj);

if (str.length >= 40) {
if (chai.Assertion.truncateThreshold && str.length >= chai.Assertion.truncateThreshold) {
if (type === '[object Function]') {
return !obj.name || obj.name === ''
? '[Function]'
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"component": "*"
, "coveralls": "2.0.16"
, "jscoverage": "0.3.7"
, "karma": "canary"
, "karma": "~0.10.5"
, "karma-mocha": "*"
, "karma-sauce-launcher": "git://github.com/embarkmobile/karma-sauce-launcher.git#feature-passfail"
, "mocha": "1.8.2"
Expand Down
29 changes: 29 additions & 0 deletions test/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,33 @@ describe('configuration', function () {
}
}
});

describe('Assertion.truncateThreshold', function() {
var orig = chai.Assertion.truncateThreshold;

beforeEach(function() {
chai.Assertion.showDiff = false;
});

afterEach(function() {
chai.Assertion.truncateThreshold = orig;
chai.Assertion.showDiff = true;
});

it('is 20', function() {
chai.Assertion.truncateThreshold = 20;

err(function() {
assert.deepEqual({v: 'something longer than 20'}, {v: 'x'});
}, "expected { Object (v) } to deeply equal { v: 'x' }");
});

it('is 0', function() {
chai.Assertion.truncateThreshold = 0;

err(function() {
assert.deepEqual({v: 'something longer than 20'}, {v: 'x'});
}, "expected { v: 'something longer than 20' } to deeply equal { v: 'x' }");
});
});
});

0 comments on commit 7ee5be9

Please sign in to comment.