forked from ipld/js-ipld-block
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.spec.js
54 lines (42 loc) · 1.16 KB
/
index.spec.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
/* eslint-env mocha */
'use strict'
const expect = require('chai').expect
const CID = require('cids')
const Block = require('../src')
describe('block', () => {
it('create throws', () => {
expect(
() => new Block('string')
).to.throw()
expect(
() => new Block(Buffer.from('hello'), 'cid')
).to.throw()
expect(
() => new Block('hello', new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n'))
).to.throw()
})
it('create', () => {
const b = new Block(Buffer.from('hello'), new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n'))
expect(Block.isBlock(b)).to.eql(true)
})
it('create with Uint8Array', () => {
const b = new Block(
new Uint8Array([104, 101, 108, 108, 111]),
new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')
)
expect(Block.isBlock(b)).to.eql(true)
})
it('block stays immutable', () => {
const b = new Block(Buffer.from('hello'), new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n'))
expect(
() => { b.data = 'fail' }
).to.throw(
/immutable/
)
expect(
() => { b.cid = 'fail' }
).to.throw(
/immutable/
)
})
})