test: fix 'checks' validation test for checkPrime
This test had two problems: * The first argument was a number in both cases, which is what caused the (expected) ERR_INVALID_ARG_TYPE error -- the validity of the 'checks' option was not actually verified at all. Thus, the first argument should be valid for this particular test. * The function returned by common.mustNotCall() was passed to assert.throws() as a third argument instead of being passed to checkPrime() as a third argument. (Isn't JavaScript great?) This again led to the (expected) ERR_INVALID_ARG_TYPE error, but again, the validity of the 'checks' option was not verified. Fix both issues by ensuring that all arguments except the 'checks' option are valid. Refs: https://github.com/nodejs/node/pull/36997 PR-URL: https://github.com/nodejs/node/pull/47139 Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
parent
843856ead7
commit
fbd526b15a
@ -229,14 +229,16 @@ generatePrime(
|
||||
});
|
||||
});
|
||||
|
||||
['hello', {}, []].forEach((i) => {
|
||||
assert.throws(() => checkPrime(2, { checks: i }), {
|
||||
code: 'ERR_INVALID_ARG_TYPE'
|
||||
}, common.mustNotCall());
|
||||
assert.throws(() => checkPrimeSync(2, { checks: i }), {
|
||||
code: 'ERR_INVALID_ARG_TYPE'
|
||||
for (const checks of ['hello', {}, []]) {
|
||||
assert.throws(() => checkPrime(2n, { checks }, common.mustNotCall()), {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
message: /checks/
|
||||
});
|
||||
});
|
||||
assert.throws(() => checkPrimeSync(2n, { checks }), {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
message: /checks/
|
||||
});
|
||||
}
|
||||
|
||||
assert(!checkPrimeSync(Buffer.from([0x1])));
|
||||
assert(checkPrimeSync(Buffer.from([0x2])));
|
||||
|
Loading…
x
Reference in New Issue
Block a user