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: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
dca7fb2225
commit
710110788b
@ -485,7 +485,7 @@ function expectsError(stackStartFn, actual, error, message) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
message = error;
|
message = error;
|
||||||
error = null;
|
error = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (actual === NO_EXCEPTION_SENTINEL) {
|
if (actual === NO_EXCEPTION_SENTINEL) {
|
||||||
@ -496,7 +496,7 @@ function expectsError(stackStartFn, actual, error, message) {
|
|||||||
details += message ? `: ${message}` : '.';
|
details += message ? `: ${message}` : '.';
|
||||||
const fnType = stackStartFn === rejects ? 'rejection' : 'exception';
|
const fnType = stackStartFn === rejects ? 'rejection' : 'exception';
|
||||||
innerFail({
|
innerFail({
|
||||||
actual,
|
actual: undefined,
|
||||||
expected: error,
|
expected: error,
|
||||||
operator: stackStartFn.name,
|
operator: stackStartFn.name,
|
||||||
message: `Missing expected ${fnType}${details}`,
|
message: `Missing expected ${fnType}${details}`,
|
||||||
@ -514,7 +514,7 @@ function expectsNoError(stackStartFn, actual, error, message) {
|
|||||||
|
|
||||||
if (typeof error === 'string') {
|
if (typeof error === 'string') {
|
||||||
message = error;
|
message = error;
|
||||||
error = null;
|
error = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!error || expectedException(actual, error)) {
|
if (!error || expectedException(actual, error)) {
|
||||||
|
@ -192,32 +192,40 @@ a.throws(() => thrower(TypeError), (err) => {
|
|||||||
const noop = () => {};
|
const noop = () => {};
|
||||||
assert.throws(
|
assert.throws(
|
||||||
() => { a.throws((noop)); },
|
() => { a.throws((noop)); },
|
||||||
common.expectsError({
|
{
|
||||||
code: 'ERR_ASSERTION',
|
code: 'ERR_ASSERTION',
|
||||||
message: /^Missing expected exception\.$/,
|
message: 'Missing expected exception.',
|
||||||
operator: 'throws'
|
operator: 'throws',
|
||||||
}));
|
actual: undefined,
|
||||||
|
expected: undefined
|
||||||
|
});
|
||||||
|
|
||||||
assert.throws(
|
assert.throws(
|
||||||
() => { a.throws(noop, TypeError); },
|
() => { a.throws(noop, TypeError); },
|
||||||
common.expectsError({
|
{
|
||||||
code: 'ERR_ASSERTION',
|
code: 'ERR_ASSERTION',
|
||||||
message: /^Missing expected exception \(TypeError\)\.$/
|
message: 'Missing expected exception (TypeError).',
|
||||||
}));
|
actual: undefined,
|
||||||
|
expected: TypeError
|
||||||
|
});
|
||||||
|
|
||||||
assert.throws(
|
assert.throws(
|
||||||
() => { a.throws(noop, 'fhqwhgads'); },
|
() => { a.throws(noop, 'fhqwhgads'); },
|
||||||
common.expectsError({
|
{
|
||||||
code: 'ERR_ASSERTION',
|
code: 'ERR_ASSERTION',
|
||||||
message: /^Missing expected exception: fhqwhgads$/
|
message: 'Missing expected exception: fhqwhgads',
|
||||||
}));
|
actual: undefined,
|
||||||
|
expected: undefined
|
||||||
|
});
|
||||||
|
|
||||||
assert.throws(
|
assert.throws(
|
||||||
() => { a.throws(noop, TypeError, 'fhqwhgads'); },
|
() => { a.throws(noop, TypeError, 'fhqwhgads'); },
|
||||||
common.expectsError({
|
{
|
||||||
code: 'ERR_ASSERTION',
|
code: 'ERR_ASSERTION',
|
||||||
message: /^Missing expected exception \(TypeError\): fhqwhgads$/
|
message: 'Missing expected exception (TypeError): fhqwhgads',
|
||||||
}));
|
actual: undefined,
|
||||||
|
expected: TypeError
|
||||||
|
});
|
||||||
|
|
||||||
let threw = false;
|
let threw = false;
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user