Skip to content

Commit

Permalink
fixup no-diff tests to use expect.js for #2536
Browse files Browse the repository at this point in the history
  • Loading branch information
boneskull committed Dec 12, 2017
1 parent 7650b01 commit ecefec8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
5 changes: 1 addition & 4 deletions lib/reporters/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,8 @@ exports.list = function (failures) {
if (err.uncaught) {
msg = 'Uncaught ' + msg;
}

// explicitly show diff
if (exports.hideDiff !== true && err.showDiff !== false && sameType(actual, expected) && expected !== undefined) {
escape = false;
if (showDiff(err)) {
if (!exports.hideDiff && showDiff(err)) {
stringifyDiffObjs(err);
fmt = color('error title', ' %s) %s:\n%s') + color('error stack', '\n%s\n');
var match = message.match(/^([^:]+): expected/);
Expand Down
30 changes: 25 additions & 5 deletions test/integration/no-diff.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,31 @@ var helpers = require('./helpers');
var run = helpers.runMocha;

describe('no-diff', function () {
it('should be honoured', function (done) {
run('no-diff.fixture.js', ['--no-diff'], function (err, res) {
res.output.should.not.match(/\+ expected/);
res.output.should.not.match(/- actual/);
done(err);
describe('when enabled', function () {
it('should not display a diff', function (done) {
run('no-diff.fixture.js', ['--no-diff'], function (err, res) {
if (err) {
done(err);
return;
}
expect(res.output).not.to.match(/\+ expected/);
expect(res.output).not.to.match(/- actual/);
done();
});
});
});

describe('when disabled', function () {
it('should display a diff', function (done) {
run('no-diff.fixture.js', ['--diff'], function (err, res) {
if (err) {
done(err);
return;
}
expect(res.output).to.match(/\+ expected/);
expect(res.output).to.match(/- actual/);
done();
});
});
});
});
4 changes: 2 additions & 2 deletions test/reporters/base.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ describe('Base reporter', function () {
Base.hideDiff = false; // Revert to original value

errOut = stdout.join('\n');
errOut.should.not.match(/\- actual/);
errOut.should.not.match(/\+ expected/);
expect(errOut).to.not.match(/- actual/);
expect(errOut).to.not.match(/\+ expected/);
});
});

Expand Down

0 comments on commit ecefec8

Please sign in to comment.