Skip to content

Commit dab1314

Browse files
author
James Halliday
committed
expected, actual, and operator keys in yaml-esque format on assertion failures
1 parent c9ca5be commit dab1314

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

lib/render.js

+23
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var Stream = require('stream');
2+
var json = typeof JSON === 'object' ? JSON : require('jsonify');
23

34
module.exports = Render;
45

@@ -57,5 +58,27 @@ function encodeResult (res, count) {
5758
else if (res.todo) output += ' # TODO';
5859

5960
output += '\n';
61+
62+
if (!res.ok) {
63+
var outer = Array(res.indent + 3).join(' ');
64+
var inner = outer + ' ';
65+
output += outer + '---\n';
66+
output += inner + 'operator: ' + res.operator + '\n';
67+
68+
var ex = json.stringify(res.expected);
69+
var ac = json.stringify(res.actual);
70+
71+
if (Math.max(ex.length, ac.length) > 65) {
72+
output += inner + 'expected:\n' + inner + ' ' + ex + '\n';
73+
output += inner + 'actual:\n' + inner + ' ' + ac + '\n';
74+
}
75+
else {
76+
output += inner + 'expected: ' + ex + '\n';
77+
output += inner + 'actual: ' + ac + '\n';
78+
}
79+
80+
output += outer + '...\n';
81+
}
82+
6083
return output;
6184
}

0 commit comments

Comments
 (0)