assert: indicate if exception message is generated

AssertionError.generatedMessage is now true when
AssertionError.message was generated from expected and actual

Fixes #5836, #6206
This commit is contained in:
Glen Mailer 2013-09-11 17:18:25 +01:00 committed by Timothy J Fontaine
parent 2b9e3fb183
commit 66b8c3c5a0
2 changed files with 11 additions and 1 deletions

View File

@ -42,7 +42,13 @@ assert.AssertionError = function AssertionError(options) {
this.actual = options.actual;
this.expected = options.expected;
this.operator = options.operator;
this.message = options.message || getMessage(this);
if (options.message) {
this.message = options.message;
this.generatedMessage = false;
} else {
this.message = getMessage(this);
this.generatedMessage = true;
}
var stackStartFunction = options.stackStartFunction || fail;
Error.captureStackTrace(this, stackStartFunction);
};

View File

@ -260,6 +260,7 @@ function testAssertionMessage(actual, expected) {
} catch (e) {
assert.equal(e.toString(),
['AssertionError:', expected, '==', '""'].join(' '));
assert.ok(e.generatedMessage, "Message not marked as generated");
}
}
testAssertionMessage(undefined, '"undefined"');
@ -299,10 +300,13 @@ try {
assert.equal(1, 2);
} catch (e) {
assert.equal(e.toString().split('\n')[0], 'AssertionError: 1 == 2')
assert.ok(e.generatedMessage, 'Message not marked as generated');
}
try {
assert.equal(1, 2, 'oh no');
} catch (e) {
assert.equal(e.toString().split('\n')[0], 'AssertionError: oh no')
assert.equal(e.generatedMessage, false,
'Message incorrectly marked as generated');
}