Skip to content

Commit a97f264

Browse files
Trottevanlucas
authored andcommitted
test: refactor test-crypto-random
* specify constructor for assert.throws() * load additional modules only if crypto check passes * normalize some potentially confusing indentation * provided actual first and expected second in assertions PR-URL: #10232 Reviewed-By: Prince John Wesley <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
1 parent 2f9c8d9 commit a97f264

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

test/parallel/test-crypto-random.js

+7-16
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,28 @@
11
'use strict';
22
const common = require('../common');
3-
const assert = require('assert');
43

54
if (!common.hasCrypto) {
65
common.skip('missing crypto');
76
return;
87
}
8+
const assert = require('assert');
99
const crypto = require('crypto');
1010

1111
crypto.DEFAULT_ENCODING = 'buffer';
1212

1313
// bump, we register a lot of exit listeners
1414
process.setMaxListeners(256);
1515

16-
[crypto.randomBytes,
17-
crypto.pseudoRandomBytes
18-
].forEach(function(f) {
19-
[-1,
20-
undefined,
21-
null,
22-
false,
23-
true,
24-
{},
25-
[]
26-
].forEach(function(value) {
27-
assert.throws(function() { f(value); });
28-
assert.throws(function() { f(value, function() {}); });
16+
[crypto.randomBytes, crypto.pseudoRandomBytes].forEach(function(f) {
17+
[-1, undefined, null, false, true, {}, []].forEach(function(value) {
18+
assert.throws(function() { f(value); }, TypeError);
19+
assert.throws(function() { f(value, function() {}); }, TypeError);
2920
});
3021

3122
[0, 1, 2, 4, 16, 256, 1024].forEach(function(len) {
3223
f(len, common.mustCall(function(ex, buf) {
33-
assert.strictEqual(null, ex);
34-
assert.strictEqual(len, buf.length);
24+
assert.strictEqual(ex, null);
25+
assert.strictEqual(buf.length, len);
3526
assert.ok(Buffer.isBuffer(buf));
3627
}));
3728
});

0 commit comments

Comments
 (0)