generated from Richienb/node-module-boilerplate
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest.js
62 lines (53 loc) · 1.34 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
import test from "ava"
import isBlob from "is-blob"
import getStream from "get-stream"
import Blob from "./index.js"
global.Blob = Blob
test("main", t => {
t.true(isBlob(new Blob([])))
})
test("size", t => {
const data = "a=1"
const blob = new Blob([data])
t.is(blob.size, data.length)
})
test("type", t => {
const data = "a=1"
const type = "text/plain"
const blob = new Blob([data], { type })
t.is(blob.type, type)
})
test("text()", async t => {
const data = "a=1"
const type = "text/plain"
const blob = new Blob([data], { type })
t.is(await blob.text(), data)
})
test("arrayBuffer()", async t => {
const data = "a=1"
const type = "text/plain"
const blob = new Blob([data], { type })
const decoder = new TextDecoder("utf-8")
const buffer = await blob.arrayBuffer()
t.is(decoder.decode(buffer), data)
})
test("stream()", async t => {
const data = "a=1"
const type = "text/plain"
const blob = new Blob([data], { type })
const result = await getStream(blob.stream())
t.is(result, data)
})
test("toString()", t => {
const data = "a=1"
const type = "text/plain"
const blob = new Blob([data], { type })
t.is(blob.toString(), "[object Blob]")
})
test("slice()", async t => {
const data = "a=1"
const type = "text/plain"
const blob = new Blob([data], { type })
const blob2 = blob.slice(0, 1)
t.is(await blob2.text(), data.slice(0, 1))
})