| 32 | } |
| 33 | |
| 34 | function createMockCanvas(): HTMLCanvasElement { |
| 35 | return { |
| 36 | width: 0, |
| 37 | height: 0, |
| 38 | getContext: (contextType: string) => { |
| 39 | if (contextType !== "2d") { |
| 40 | return null; |
| 41 | } |
| 42 | |
| 43 | return { |
| 44 | drawImage: (_image: unknown, _x: number, _y: number, width: number, height: number) => { |
| 45 | drawImageCalls.push({ width, height }); |
| 46 | }, |
| 47 | } as unknown as CanvasRenderingContext2D; |
| 48 | }, |
| 49 | toDataURL: (type?: string, quality?: number) => { |
| 50 | toDataUrlCalls.push({ type, quality }); |
| 51 | return `data:${type ?? "image/png"};base64,resized`; |
| 52 | }, |
| 53 | } as unknown as HTMLCanvasElement; |
| 54 | } |
| 55 | |
| 56 | beforeEach(() => { |
| 57 | mockImageWidth = 0; |