diff --git a/lib/internal/assert/assertion_error.js b/lib/internal/assert/assertion_error.js index 048d7be75fc662..b0226e879ad9ba 100644 --- a/lib/internal/assert/assertion_error.js +++ b/lib/internal/assert/assertion_error.js @@ -298,7 +298,9 @@ class AssertionError extends Error { const { message, operator, - stackStartFn + stackStartFn, + // Compatibility with older versions. + stackStartFunction } = options; let { actual, @@ -418,7 +420,7 @@ class AssertionError extends Error { this.expected = expected; this.operator = operator; // eslint-disable-next-line no-restricted-syntax - Error.captureStackTrace(this, stackStartFn); + Error.captureStackTrace(this, stackStartFn || stackStartFunction); // Create error message including the error code in the name. this.stack; // Reset the name. diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js index b7d81f549547ed..34dc8fabdef04b 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -1203,3 +1203,21 @@ assert.throws( () => a.deepStrictEqual(), { code: 'ERR_MISSING_ARGS' } ); + +// Verify that `stackStartFunction` works as alternative to `stackStartFn`. +{ + (function hidden() { + const err = new assert.AssertionError({ + actual: 'foo', + operator: 'strictEqual', + stackStartFunction: hidden + }); + const err2 = new assert.AssertionError({ + actual: 'foo', + operator: 'strictEqual', + stackStartFn: hidden + }); + assert(!err.stack.includes('hidden')); + assert(!err2.stack.includes('hidden')); + })(); +}