-
Notifications
You must be signed in to change notification settings - Fork 520
/
Copy pathconvertToBlob.test.js
40 lines (35 loc) · 1.16 KB
/
convertToBlob.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
const test = require('ava')
const { convertToBlob } = require('./index')
test('convert strings', (t) => {
let ablob = convertToBlob({ data: ['test'], mimeType: 'test1' })
t.is(ablob.size, 4)
t.is(ablob.type, 'test1')
t.is(ablob.isClosed, false)
t.is(ablob.encoding, 'utf8')
t.is(ablob.length, 4)
t.not(ablob.buffer, null)
ablob = convertToBlob({ data: ['1FAE', '0c8a'], mimeType: 'test2' })
t.is(ablob.size, 8)
t.is(ablob.type, 'test2')
t.is(ablob.isClosed, false)
t.is(ablob.encoding, 'utf8')
t.is(ablob.length, 8)
t.not(ablob.buffer, null)
})
test('convert array buffers', (t) => {
let ablob = convertToBlob({ data: [Int32Array.from('12345').buffer], mimeType: 'test3' })
t.is(ablob.size, 20)
t.is(ablob.type, 'test3')
t.is(ablob.isClosed, false)
t.is(ablob.encoding, 'utf8')
t.is(ablob.length, 20)
t.not(ablob.buffer, null)
// multiple buffers
ablob = convertToBlob({ data: [Int32Array.from('12345').buffer, Int16Array.from('67890').buffer], mimeType: 'test4' })
t.is(ablob.size, 30)
t.is(ablob.type, 'test4')
t.is(ablob.isClosed, false)
t.is(ablob.encoding, 'utf8')
t.is(ablob.length, 30)
t.not(ablob.buffer, null)
})