24 lines
769 B
TypeScript
24 lines
769 B
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
import { loadSvg } from '@/anatomy/svgLoader'
|
|
|
|
const SVG = '<svg xmlns="http://www.w3.org/2000/svg"><g data-bone-id="x"/></svg>'
|
|
|
|
describe('loadSvg', () => {
|
|
beforeEach(() => {
|
|
vi.stubGlobal('fetch', vi.fn(async () => ({
|
|
ok: true,
|
|
text: async () => SVG,
|
|
})) as unknown as typeof fetch)
|
|
})
|
|
|
|
it('returns an SVGSVGElement', async () => {
|
|
const root = await loadSvg('/whatever.svg')
|
|
expect(root.tagName.toLowerCase()).toBe('svg')
|
|
})
|
|
|
|
it('throws on non-ok response', async () => {
|
|
vi.stubGlobal('fetch', vi.fn(async () => ({ ok: false, status: 404, text: async () => '' })) as unknown as typeof fetch)
|
|
await expect(loadSvg('/missing.svg')).rejects.toThrow()
|
|
})
|
|
})
|