MCPcopy Create free account
hub / github.com/dfinity/orbit / mockFileReader

Function mockFileReader

apps/wallet/src/test.utils.ts:92–116  ·  view source on GitHub ↗
(result: ArrayBuffer, errorOut: boolean = false)

Source from the content-addressed store, hash-verified

90}
91
92export function mockFileReader(result: ArrayBuffer, errorOut: boolean = false): typeof FileReader {
93 return class MockFileReader {
94 result?: ArrayBuffer = result;
95 // eslint-disable-next-line @typescript-eslint/no-explicit-any
96 onload: any = null;
97 // eslint-disable-next-line @typescript-eslint/no-explicit-any
98 onerror: any | null = null;
99
100 readAsArrayBuffer(_file: File): void {
101 this.result = result;
102
103 if (errorOut) {
104 setTimeout(() => this.onerror?.(new ProgressEvent('error')));
105 } else {
106 // eslint-disable-next-line @typescript-eslint/no-explicit-any
107 setTimeout(() => this.onload?.(new ProgressEvent('load', { target: this } as any)));
108 }
109 }
110
111 // Mimicking static properties of the FileReader
112 static EMPTY = 0;
113 static LOADING = 1;
114 static DONE = 2;
115 } as unknown as typeof FileReader;
116}

Callers 1

file.utils.spec.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected