Skip to content

Commit

Permalink
omit expected and actual if there is no actual or expected
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Mar 5, 2014
1 parent 45add17 commit b6ac9bf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
26 changes: 16 additions & 10 deletions lib/results.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,18 @@ function encodeResult (res, count) {
output += outer + '---\n';
output += inner + 'operator: ' + res.operator + '\n';

var ex = inspect(res.expected);
var ac = inspect(res.actual);

if (Math.max(ex.length, ac.length) > 65) {
output += inner + 'expected:\n' + inner + ' ' + ex + '\n';
output += inner + 'actual:\n' + inner + ' ' + ac + '\n';
}
else {
output += inner + 'expected: ' + ex + '\n';
output += inner + 'actual: ' + ac + '\n';
if (has(res, 'expected') || has(res, 'actual')) {
var ex = inspect(res.expected);
var ac = inspect(res.actual);

if (Math.max(ex.length, ac.length) > 65) {
output += inner + 'expected:\n' + inner + ' ' + ex + '\n';
output += inner + 'actual:\n' + inner + ' ' + ac + '\n';
}
else {
output += inner + 'expected: ' + ex + '\n';
output += inner + 'actual: ' + ac + '\n';
}
}
if (res.at) {
output += inner + 'at: ' + res.at + '\n';
Expand Down Expand Up @@ -181,3 +183,7 @@ function getNextTest (results) {
}
} while (results.tests.length !== 0)
}

function has (obj, prop) {
return Object.prototype.hasOwnProperty.call(obj, prop);
}
17 changes: 12 additions & 5 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,10 @@ Test.prototype.end = function (err) {
};

Test.prototype._end = function (err) {
var self = this;
if (this._progeny.length) {
var t = this._progeny.shift();
t.on('end', function () {
self._end();
});
t.on('end', function () { self._end() });
t.run();
return;
}
Expand Down Expand Up @@ -166,9 +165,13 @@ Test.prototype._assert = function assert (ok, opts) {
skip : defined(extra.skip, opts.skip),
name : defined(extra.message, opts.message, '(unnamed assert)'),
operator : defined(extra.operator, opts.operator),
actual : defined(extra.actual, opts.actual),
expected : defined(extra.expected, opts.expected)
};
if (has(opts, 'actual') || has(extra, 'actual')) {
res.actual = defined(extra.actual, opts.actual);
}
if (has(opts, 'expected') || has(extra, 'expected')) {
res.expected = defined(extra.expected, opts.expected);
}
this._ok = Boolean(this._ok && ok);

if (!ok) {
Expand Down Expand Up @@ -436,4 +439,8 @@ Test.prototype.doesNotThrow = function (fn, expected, msg, extra) {
});
};

function has (obj, prop) {
return Object.prototype.hasOwnProperty.call(obj, prop);
}

// vim: set softtabstop=4 shiftwidth=4:

0 comments on commit b6ac9bf

Please sign in to comment.