From 45e7b10287ca09df07ef2066419494467cd65850 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Sun, 19 Mar 2023 17:48:04 +0100 Subject: [PATCH] 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 Reviewed-By: Luigi Pinca --- test/parallel/test-crypto-prime.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/test/parallel/test-crypto-prime.js b/test/parallel/test-crypto-prime.js index 88eca54bb90560..5eef83fb266bb8 100644 --- a/test/parallel/test-crypto-prime.js +++ b/test/parallel/test-crypto-prime.js @@ -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])));