diff --git a/lib/assert.js b/lib/assert.js index 828a443ec9290a..e5ea6e049ce51c 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -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 { diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js index 3db63a816a5294..952766c0fc0d25 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -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), {