Skip to content

Commit 87917ca

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 d2c3fef commit 87917ca

2 files changed

Lines changed: 24 additions & 16 deletions

File tree

lib/assert.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ function expectsError(stackStartFn, actual, error, message) {
290290
error);
291291
}
292292
message = error;
293-
error = null;
293+
error = undefined;
294294
}
295295

296296
if (actual === NO_EXCEPTION_SENTINEL) {
@@ -301,7 +301,7 @@ function expectsError(stackStartFn, actual, error, message) {
301301
details += message ? `: ${message}` : '.';
302302
const fnType = stackStartFn === rejects ? 'rejection' : 'exception';
303303
innerFail({
304-
actual,
304+
actual: undefined,
305305
expected: error,
306306
operator: stackStartFn.name,
307307
message: `Missing expected ${fnType}${details}`,
@@ -319,7 +319,7 @@ function expectsNoError(stackStartFn, actual, error, message) {
319319

320320
if (typeof error === 'string') {
321321
message = error;
322-
error = null;
322+
error = undefined;
323323
}
324324

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

test/parallel/test-assert.js

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -198,32 +198,40 @@ a.throws(() => thrower(TypeError), (err) => {
198198
const noop = () => {};
199199
assert.throws(
200200
() => { a.throws((noop)); },
201-
common.expectsError({
201+
{
202202
code: 'ERR_ASSERTION',
203-
message: /^Missing expected exception\.$/,
204-
operator: 'throws'
205-
}));
203+
message: 'Missing expected exception.',
204+
operator: 'throws',
205+
actual: undefined,
206+
expected: undefined
207+
});
206208

207209
assert.throws(
208210
() => { a.throws(noop, TypeError); },
209-
common.expectsError({
211+
{
210212
code: 'ERR_ASSERTION',
211-
message: /^Missing expected exception \(TypeError\)\.$/
212-
}));
213+
message: 'Missing expected exception (TypeError).',
214+
actual: undefined,
215+
expected: TypeError
216+
});
213217

214218
assert.throws(
215219
() => { a.throws(noop, 'fhqwhgads'); },
216-
common.expectsError({
220+
{
217221
code: 'ERR_ASSERTION',
218-
message: /^Missing expected exception: fhqwhgads$/
219-
}));
222+
message: 'Missing expected exception: fhqwhgads',
223+
actual: undefined,
224+
expected: undefined
225+
});
220226

221227
assert.throws(
222228
() => { a.throws(noop, TypeError, 'fhqwhgads'); },
223-
common.expectsError({
229+
{
224230
code: 'ERR_ASSERTION',
225-
message: /^Missing expected exception \(TypeError\): fhqwhgads$/
226-
}));
231+
message: 'Missing expected exception (TypeError): fhqwhgads',
232+
actual: undefined,
233+
expected: TypeError
234+
});
227235

228236
let threw = false;
229237
try {

0 commit comments

Comments
 (0)