forked from nodejs/undici
/
file.js
64 lines (56 loc) · 1.59 KB
/
file.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
'use strict'
const { test } = require('tap')
const { File, FileLike } = require('../../lib/fetch/file')
test('args validation', (t) => {
t.plan(14)
t.throws(() => {
File.prototype.name.call(null)
}, TypeError)
t.throws(() => {
File.prototype.lastModified.call(null)
}, TypeError)
t.doesNotThrow(() => {
File.prototype[Symbol.toStringTag].charAt(0)
}, TypeError)
t.throws(() => {
FileLike.prototype.stream.call(null)
}, TypeError)
t.throws(() => {
FileLike.prototype.arrayBuffer.call(null)
}, TypeError)
t.throws(() => {
FileLike.prototype.slice.call(null)
}, TypeError)
t.throws(() => {
FileLike.prototype.text.call(null)
}, TypeError)
t.throws(() => {
FileLike.prototype.size.call(null)
}, TypeError)
t.throws(() => {
FileLike.prototype.type.call(null)
}, TypeError)
t.throws(() => {
FileLike.prototype.name.call(null)
}, TypeError)
t.throws(() => {
FileLike.prototype.lastModified.call(null)
}, TypeError)
t.doesNotThrow(() => {
FileLike.prototype[Symbol.toStringTag].charAt(0)
}, TypeError)
t.equal(File.prototype[Symbol.toStringTag], 'File')
t.equal(FileLike.prototype[Symbol.toStringTag], 'File')
})
test('return value of File.lastModified', (t) => {
t.plan(2)
const f = new File(['asd1'], 'filename123')
const lastModified = f.lastModified
t.ok(typeof lastModified === typeof Date.now())
t.ok(lastModified >= 0 && lastModified <= Date.now())
})
test('Symbol.toStringTag', (t) => {
t.plan(2)
t.equal(new File()[Symbol.toStringTag], 'File')
t.equal(new FileLike()[Symbol.toStringTag], 'File')
})