Files
oh-my-pi/packages/coding-agent/test/image-input-normalization.test.ts
T
can1357 df369dd7fd refactor(coding-agent): migrated test mocks to vitest spyOn with Symbol.dispose cleanup
- 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.
2026-03-26 16:17:27 +01:00

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" });
});
});