df369dd7fd
- Migrated test mocking from bun:test mock API to vitest spyOn pattern across 9 test files. - Extracted mock setup logic into reusable helper functions with Symbol.dispose cleanup pattern. - Replaced manual beforeEach/afterEach and try-finally blocks with TypeScript 5.2 using declarations. - Removed 178 lines of boilerplate mock initialization and restoration code from test suite.
31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
import { afterEach, describe, expect, test, vi } from "bun:test";
|
|
import * as imageConvert from "../src/utils/image-convert";
|
|
import { ensureSupportedImageInput } from "../src/utils/image-input";
|
|
|
|
describe("ensureSupportedImageInput", () => {
|
|
afterEach(() => {
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
test("returns supported image input unchanged", async () => {
|
|
const convertToPngSpy = vi.spyOn(imageConvert, "convertToPng");
|
|
const input = { type: "image" as const, data: "abc", mimeType: "image/png" };
|
|
|
|
const result = await ensureSupportedImageInput(input);
|
|
|
|
expect(result).toEqual(input);
|
|
expect(convertToPngSpy).not.toHaveBeenCalled();
|
|
});
|
|
|
|
test("converts unsupported image input to png", async () => {
|
|
const convertToPngSpy = vi
|
|
.spyOn(imageConvert, "convertToPng")
|
|
.mockResolvedValue({ data: "pngdata", mimeType: "image/png" });
|
|
|
|
const result = await ensureSupportedImageInput({ type: "image", data: "bmpdata", mimeType: "image/bmp" });
|
|
|
|
expect(convertToPngSpy).toHaveBeenCalledWith("bmpdata", "image/bmp");
|
|
expect(result).toEqual({ type: "image", data: "pngdata", mimeType: "image/png" });
|
|
});
|
|
});
|