Skip to content

Commit

Permalink
Merge pull request #680 from polomsky/inspect-fix
Browse files Browse the repository at this point in the history
Fix failure when custom inspect method is used
  • Loading branch information
lucasfcosta committed Apr 18, 2016
2 parents e6c620a + bdd558e commit d96937a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/chai/utils/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function formatValue(ctx, value, recurseTimes) {
value.inspect !== exports.inspect &&
// Also filter out any prototype objects using the circular check.
!(value.constructor && value.constructor.prototype === value)) {
var ret = value.inspect(recurseTimes);
var ret = value.inspect(recurseTimes, ctx);
if (typeof ret !== 'string') {
ret = formatValue(ctx, ret, recurseTimes);
}
Expand Down
13 changes: 13 additions & 0 deletions test/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,19 @@ describe('utilities', function () {
});
});

it('inspect with custom stylize-calling inspect()s', function () {
chai.use(function (_chai, _) {
var obj = {
outer: {
inspect: function (depth, options) {
return options.stylize('Object content', 'string');
}
}
};
expect(_.inspect(obj)).to.equal('{ outer: Object content }');
});
});

it('inspect with custom object-returning inspect()s', function () {
chai.use(function (_chai, _) {
var obj = {
Expand Down

0 comments on commit d96937a

Please sign in to comment.