Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80542 views
1
var test = require("tape");
2
var randomBytes = require('./');
3
4
test('sync', function (t) {
5
t.plan(3);
6
t.equals(randomBytes(3).length, 3, 'len: ' + 3);
7
t.equals(randomBytes(30).length, 30, 'len: ' + 30);
8
t.equals(randomBytes(300).length, 300, 'len: ' + 300);
9
});
10
test('async', function (t) {
11
t.plan(3);
12
randomBytes(3, function (err, resp) {
13
t.equals(resp.length, 3, 'len: ' + 3);
14
});
15
randomBytes(30, function (err, resp) {
16
t.equals(resp.length, 30, 'len: ' + 30);
17
});
18
randomBytes(300, function (err, resp) {
19
t.equals(resp.length, 300, 'len: ' + 300);
20
});
21
});
22
if (process.browser) {
23
test('requesting to much throws', function (t) {
24
t.plan(1);
25
t.throws(randomBytes.bind(null, 65537));
26
});
27
test('requesting to much throws async', function (t) {
28
t.plan(1);
29
t.throws(randomBytes.bind(null, 65537, function () {
30
t.ok(false, 'should not get here');
31
}));
32
});
33
}
34