| 90 | } |
| 91 | |
| 92 | export 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 | } |