Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
assert: fix misformatted error message
Before: `Missing expected exception..`

Afer: `Missing expected exception.`
  • Loading branch information
Trott committed Feb 10, 2017
commit 9df45db482e613c8d539826fc9bfaa9782fb04e0
2 changes: 1 addition & 1 deletion lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ function _throws(shouldThrow, block, expected, message) {
actual = _tryBlock(block);

message = (expected && expected.name ? ' (' + expected.name + ').' : '.') +
(message ? ' ' + message : '.');
(message ? ' ' + message : '');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this end with . when message is truthy?

(message ? ` ${message}.` : '');

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, unless message is expected to already end with ., so ¯\(ツ)/¯. And there should also be a : rather than . after expected if message is truthy.

Thinking about this some more and looking at the uses, I wonder if the thing to do is get rid of all the logic for appending . in the first place. Nothing else appends .. And this mostly only seems to do it wrong!

Current master results in messages like this:

AssertionError: Missing expected exception..
AssertionError: Missing expected exception. foo bar baz

wat?

Compare to assert.strictEqual() which does not append .:

AssertionError: 'a' === 'b'
AssertionError: foo bar baz

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lpinca OK, I just pushed some improvements based on your comment. PTAL


if (shouldThrow && !actual) {
fail(actual, expected, 'Missing expected exception' + message);
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ testAssertionMessage({a: NaN, b: Infinity, c: -Infinity},
});
} catch (e) {
threw = true;
assert.strictEqual(e.message, 'Missing expected exception..');
assert.strictEqual(e.message, 'Missing expected exception.');
}
assert.ok(threw);
}
Expand Down