31
packages/coding-agent/test/clipboard-native.test.ts
Normal file
31
packages/coding-agent/test/clipboard-native.test.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { describe, expect, test, vi } from "vitest";
|
||||
import { type ClipboardModule, loadClipboardNative } from "../src/utils/clipboard-native.ts";
|
||||
|
||||
type ClipboardRequire = (id: string) => unknown;
|
||||
|
||||
const fakeClipboard: ClipboardModule = {
|
||||
setText: async () => {},
|
||||
hasImage: () => true,
|
||||
getImageBinary: async () => [1, 2, 3],
|
||||
};
|
||||
|
||||
describe("loadClipboardNative", () => {
|
||||
test("falls back to the next require root", () => {
|
||||
const primary = vi.fn<ClipboardRequire>(() => {
|
||||
throw new Error("missing from bundled root");
|
||||
});
|
||||
const fallback = vi.fn<ClipboardRequire>(() => fakeClipboard);
|
||||
|
||||
expect(loadClipboardNative([primary, fallback])).toBe(fakeClipboard);
|
||||
expect(primary).toHaveBeenCalledWith("@mariozechner/clipboard");
|
||||
expect(fallback).toHaveBeenCalledWith("@mariozechner/clipboard");
|
||||
});
|
||||
|
||||
test("returns null when no require root can load clipboard", () => {
|
||||
const missing = vi.fn<ClipboardRequire>(() => {
|
||||
throw new Error("missing");
|
||||
});
|
||||
|
||||
expect(loadClipboardNative([missing])).toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user