mirror of
https://github.com/earendil-works/pi.git
synced 2026-06-18 15:54:04 +08:00
3f89350cef
closes #4307
32 lines
1.0 KiB
TypeScript
32 lines
1.0 KiB
TypeScript
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();
|
|
});
|
|
});
|