mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
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:
parent
2b9e3fb183
commit
66b8c3c5a0
@ -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);
|
||||
};
|
||||
|
@ -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');
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user