mirror of
https://github.com/fluencelabs/js-libp2p-crypto
synced 2025-06-22 10:21:33 +00:00
chore: add error codes (#155)
* chore: add error codes * chore: create errors with new Error() * fix: better error testin * refactor: simplify random bytes error checks
This commit is contained in:
27
test/random-bytes.spec.js
Normal file
27
test/random-bytes.spec.js
Normal file
@ -0,0 +1,27 @@
|
||||
/* eslint-env mocha */
|
||||
'use strict'
|
||||
|
||||
const chai = require('chai')
|
||||
const dirtyChai = require('dirty-chai')
|
||||
const expect = chai.expect
|
||||
chai.use(dirtyChai)
|
||||
|
||||
const randomBytes = require('../src/random-bytes')
|
||||
|
||||
describe('randomBytes', () => {
|
||||
it('produces random bytes', () => {
|
||||
expect(randomBytes(16)).to.have.length(16)
|
||||
})
|
||||
|
||||
it('throws if length is 0', () => {
|
||||
expect(() => randomBytes(0)).to.throw(Error).with.property('code', 'ERR_INVALID_LENGTH')
|
||||
})
|
||||
|
||||
it('throws if length is < 0', () => {
|
||||
expect(() => randomBytes(-1)).to.throw(Error).with.property('code', 'ERR_INVALID_LENGTH')
|
||||
})
|
||||
|
||||
it('throws if length is not a number', () => {
|
||||
expect(() => randomBytes('hi')).to.throw(Error).with.property('code', 'ERR_INVALID_LENGTH')
|
||||
})
|
||||
})
|
Reference in New Issue
Block a user