return [this.name + ':', this.message].join(' ');
} else {
return [this.name + ':',
- JSON.stringify(this.expected),
+ JSON.stringify(this.expected, replacer),
this.operator,
- JSON.stringify(this.actual)].join(' ');
+ JSON.stringify(this.actual, replacer)].join(' ');
+ }
+ function replacer(key, value) {
+ if (value === undefined) {
+ return '' + value;
+ }
+ if (typeof value === 'number' && (isNaN(value) || !isFinite(value))) {
+ return value.toString();
+ }
+ if (typeof value === 'function' || value instanceof RegExp) {
+ return value.toString();
+ }
+ return value;
}
};
console.log('All OK');
assert.ok(gotError);
+
+// #217
+function testAssertionMessage(actual, expected) {
+ try {
+ assert.equal(actual, '');
+ } catch (e) {
+ assert.equal(e.toString(),
+ ['AssertionError:', '""', '==', expected].join(' '));
+ }
+}
+testAssertionMessage(undefined, '"undefined"');
+testAssertionMessage(null, 'null');
+testAssertionMessage(true, 'true');
+testAssertionMessage(false, 'false');
+testAssertionMessage(0, '0');
+testAssertionMessage(100, '100');
+testAssertionMessage(NaN, '"NaN"');
+testAssertionMessage(Infinity, '"Infinity"');
+testAssertionMessage(-Infinity, '"-Infinity"');
+testAssertionMessage('', '""');
+testAssertionMessage('foo', '"foo"');
+testAssertionMessage([], '[]');
+testAssertionMessage([1,2,3], '[1,2,3]');
+testAssertionMessage(/a/, '"/a/"');
+testAssertionMessage(/abc/gim, '"/abc/gim"');
+testAssertionMessage(function f() {}, '"function f() {}"');
+testAssertionMessage({}, '{}');
+testAssertionMessage({a:undefined, b:null}, '{"a":"undefined","b":null}');
+testAssertionMessage({a:NaN, b:Infinity, c:-Infinity},
+ '{"a":"NaN","b":"Infinity","c":"-Infinity"}');
+