forked from angelamelinda/csvautofilljs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setupFile.ts
47 lines (40 loc) · 1.21 KB
/
setupFile.ts
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
import { JSDOM } from 'jsdom'
import * as Papa from 'papaparse'
const globalAny: any = global
const documentHTML = '<!DOCTYPE html><html><body><div id="root"></div></body></html>'
globalAny.document = new JSDOM(documentHTML).window.document
globalAny.File = class MockFile {
name: string
type: string | undefined
bits: (string | Blob | ArrayBuffer | ArrayBufferView)[]
constructor(
parts: (string | Blob | ArrayBuffer | ArrayBufferView)[],
name: string,
properties: FilePropertyBag
) {
this.bits = parts
this.name = name
this.type = properties.type
}
}
globalAny.parse = class Papa {
file: File
constructor(file: File, config?: Papa.ParseConfig | undefined) {
this.file = file
}
}
globalAny.FileReaderSync = class MockFileReaderSync {
// tslint:disable-next-line:no-empty
readAsArrayBuffer(blob: Blob) {}
// tslint:disable-next-line:no-empty
readAsBinaryString(blob: Blob) {}
// tslint:disable-next-line:no-empty
readAsText(blob: Blob) {}
// tslint:disable-next-line:no-empty
readAsDataUrl(blob: Blob) {}
}
const reader = new globalAny.FileReaderSync()
globalAny.FileReader = class MockFileReader {
// tslint:disable-next-line:no-empty
readAsText(blob: Blob) {}
}