Skip to content

Commit

Permalink
diff: Output something reasonable when there's no built-in diff for t…
Browse files Browse the repository at this point in the history
…he operands, eg. for numbers.
  • Loading branch information
papandreou committed Jan 18, 2015
1 parent 97b2d8f commit 5135471
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/uninspected.js
Expand Up @@ -58,8 +58,13 @@ uninspected.diff = function (a, b) {
var result = unexpected.diff(a, b);
if (result && result.diff) {
uninspected.log(result.diff);
} else {
} else if (unexpected.equal(a, b)) {
uninspected.log(a);
} else {
uninspected.log(unexpected.output.clone()
.text('-').append(unexpected.inspect(a)).nl()
.text('+').append(unexpected.inspect(b))
);
}
};

Expand Down
10 changes: 10 additions & 0 deletions test/uninspected.js
Expand Up @@ -80,5 +80,15 @@ describe('uninspected', function () {
);
console.log.restore(); // Cannot do this in an afterEach as it'll suppress mocha's output
});

it('should do something reasonable when diffing primitive values with no specific built-in diff', function () {
uninspected.outputFormat = 'text';
uninspected.diff(123, 456);
expect(console.log, 'was called with',
'-123\n' +
'+456'
);
console.log.restore(); // Cannot do this in an afterEach as it'll suppress mocha's output
});
});
});

0 comments on commit 5135471

Please sign in to comment.