Skip to content

Commit

Permalink
lib: fix exception message for assert(0) on try block
Browse files Browse the repository at this point in the history
  • Loading branch information
himself65 committed Dec 11, 2019
1 parent 7629fb2 commit b24246f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ function parseCode(code, offset) {
}
let node;
let start = 0;
const regExp = code.match(/^.*try.*?{/);
if (regExp != null)
start = regExp.index + regExp[0].length;
// Parse the read code until the correct expression is found.
do {
try {
Expand Down
23 changes: 23 additions & 0 deletions test/parallel/test-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,29 @@ a.throws(
/* eslint-enable no-restricted-properties */
}

common.expectsError(() => {
/* eslint-disable-next-line no-useless-catch, brace-style */
try { assert.ok(0);
} catch (err) {
throw err;
}
}, {
type: assert.AssertionError,
generatedMessage: true,
message: 'The expression evaluated to a falsy value:\n\n ' +
'assert.ok(0)\n'
});

common.expectsError(
() => assert.ok(0),
{
type: assert.AssertionError,
generatedMessage: true,
message: 'The expression evaluated to a falsy value:\n\n ' +
'assert.ok(0)\n'
}
);

common.expectsError(
() => assert.ok(null),
{
Expand Down

0 comments on commit b24246f

Please sign in to comment.