-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtest.js
69 lines (50 loc) · 1.65 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
var chai = require('chai');
var assert = chai.assert;
var randomHex = require('./src/index.js');
describe('randomHex', function () {
it('should generate random bytes with a specific length sync', function () {
assert.equal(randomHex(0).length, 2 + 0)
assert.equal(randomHex(3).length, 2 + 6)
assert.equal(randomHex(30).length, 2 + 60)
assert.equal(randomHex(300).length, 2 + 600)
assert.isTrue(/^0x[a-f0-9]+$/.test(randomHex(300)));
});
it('should generate random bytes with a specific length async', function (done) {
randomHex(0, function (err, resp) {
if (err) throw err
assert.equal(resp.length, 2 + 0);
done();
})
});
it('should generate random bytes with a specific length async', function (done) {
randomHex(3, function (err, resp) {
if (err) throw err
assert.equal(resp.length, 2 + 6);
done();
})
});
it('should generate random bytes with a specific length async', function (done) {
randomHex(30, function (err, resp) {
if (err) throw err
assert.equal(resp.length, 2 + 60);
assert.isTrue(/^0x[a-f0-9]+$/.test(resp));
done();
})
});
it('should generate random bytes with a specific length async', function (done) {
randomHex(300, function (err, resp) {
if (err) throw err
assert.equal(resp.length, 2 + 600);
done();
})
});
it('requesting to much throws sync', function () {
assert.throws(randomHex.bind(null, 65537));
});
it('requesting to much throws async', function (done) {
randomHex(65537, function (err, res) {
assert.isTrue(err instanceof Error);
done();
})
});
});