Skip to content

Commit 7101107

Browse files
committed
assert: fix actual & expected input
This makes sure the actual and expected values on the error thrown by `assert.throws` etc. are always as they should be. PR-URL: nodejs#19925 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent dca7fb2 commit 7101107

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

lib/assert.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ function expectsError(stackStartFn, actual, error, message) {
485485
);
486486
}
487487
message = error;
488-
error = null;
488+
error = undefined;
489489
}
490490

491491
if (actual === NO_EXCEPTION_SENTINEL) {
@@ -496,7 +496,7 @@ function expectsError(stackStartFn, actual, error, message) {
496496
details += message ? `: ${message}` : '.';
497497
const fnType = stackStartFn === rejects ? 'rejection' : 'exception';
498498
innerFail({
499-
actual,
499+
actual: undefined,
500500
expected: error,
501501
operator: stackStartFn.name,
502502
message: `Missing expected ${fnType}${details}`,
@@ -514,7 +514,7 @@ function expectsNoError(stackStartFn, actual, error, message) {
514514

515515
if (typeof error === 'string') {
516516
message = error;
517-
error = null;
517+
error = undefined;
518518
}
519519

520520
if (!error || expectedException(actual, error)) {

test/parallel/test-assert.js

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -192,32 +192,40 @@ a.throws(() => thrower(TypeError), (err) => {
192192
const noop = () => {};
193193
assert.throws(
194194
() => { a.throws((noop)); },
195-
common.expectsError({
195+
{
196196
code: 'ERR_ASSERTION',
197-
message: /^Missing expected exception\.$/,
198-
operator: 'throws'
199-
}));
197+
message: 'Missing expected exception.',
198+
operator: 'throws',
199+
actual: undefined,
200+
expected: undefined
201+
});
200202

201203
assert.throws(
202204
() => { a.throws(noop, TypeError); },
203-
common.expectsError({
205+
{
204206
code: 'ERR_ASSERTION',
205-
message: /^Missing expected exception \(TypeError\)\.$/
206-
}));
207+
message: 'Missing expected exception (TypeError).',
208+
actual: undefined,
209+
expected: TypeError
210+
});
207211

208212
assert.throws(
209213
() => { a.throws(noop, 'fhqwhgads'); },
210-
common.expectsError({
214+
{
211215
code: 'ERR_ASSERTION',
212-
message: /^Missing expected exception: fhqwhgads$/
213-
}));
216+
message: 'Missing expected exception: fhqwhgads',
217+
actual: undefined,
218+
expected: undefined
219+
});
214220

215221
assert.throws(
216222
() => { a.throws(noop, TypeError, 'fhqwhgads'); },
217-
common.expectsError({
223+
{
218224
code: 'ERR_ASSERTION',
219-
message: /^Missing expected exception \(TypeError\): fhqwhgads$/
220-
}));
225+
message: 'Missing expected exception (TypeError): fhqwhgads',
226+
actual: undefined,
227+
expected: TypeError
228+
});
221229

222230
let threw = false;
223231
try {

0 commit comments

Comments
 (0)