22 lines
872 B
TypeScript
22 lines
872 B
TypeScript
import { describe, it, expect, vi } from 'vitest'
|
|
import { rasterizeSvg } from '@/pdf/render/svgToPng'
|
|
|
|
vi.mock('canvg', () => ({
|
|
Canvg: { from: vi.fn(async () => ({ render: vi.fn(async () => {}) })) },
|
|
}))
|
|
|
|
describe('rasterizeSvg', () => {
|
|
it('returns a Uint8Array', async () => {
|
|
const canvas = document.createElement('canvas')
|
|
canvas.getContext = (() => ({})) as unknown as HTMLCanvasElement['getContext']
|
|
canvas.toBlob = ((cb: BlobCallback) => {
|
|
cb(new Blob([new Uint8Array([1, 2, 3])], { type: 'image/png' }))
|
|
}) as HTMLCanvasElement['toBlob']
|
|
vi.spyOn(document, 'createElement').mockImplementationOnce(() => canvas)
|
|
|
|
const out = await rasterizeSvg('<svg xmlns="http://www.w3.org/2000/svg" width="10" height="10" viewBox="0 0 10 10"/>', 2)
|
|
expect(out).toBeInstanceOf(Uint8Array)
|
|
expect(out.length).toBeGreaterThan(0)
|
|
})
|
|
})
|