Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions src/hooks/__tests__/useCopyToClipboard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,30 +132,6 @@ describe("useCopyToClipboard", () => {
);
});


it("should log error if both clipboard.writeText and fallback throw errors", async () => {
const writeError = new Error("Clipboard write error");
const execError = new Error("execCommand thrown error");

vi.mocked(navigator.clipboard.writeText).mockRejectedValue(writeError);
vi.mocked(document.execCommand).mockImplementation(() => {
throw execError;
});

const { result } = renderHook(() => useCopyToClipboard());

await act(async () => {
await result.current.copyToClipboard("failed text");
});

expect(result.current.copied).toBe(false);
expect(logger.error).toHaveBeenCalledWith(
"Failed to copy",
writeError,
execError
);
});

it("should log error if fallback throws an error", async () => {
// @ts-expect-error test setup
delete navigator.clipboard;
Expand Down
12 changes: 12 additions & 0 deletions src/lib/__tests__/cardSettings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ describe("cardSettings", () => {
});

describe("loadCardSettings", () => {
it("falls back to default settings when localStorage throws an error", () => {
getItemMock.mockImplementation(() => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

According to the repository's general rules, mock implementations in TypeScript should have explicit return types to maintain type safety and readability. Please add an explicit return type of string | null to the mock implementation.

Suggested change
getItemMock.mockImplementation(() => {
getItemMock.mockImplementation((): string | null => {
References
  1. In TypeScript, ensure functions and mock implementations have explicit return types and use async functions for mocks returning Promises to maintain type safety and readability.

throw new Error("Access Denied");
});

const result = loadCardSettings();

expect(result.layout).toEqual(DEFAULT_CARD_LAYOUT);
expect(result.options.showCompany).toBe(true);
expect(getItemMock).toHaveBeenCalledTimes(1);
});

it("returns defaults when window is undefined", () => {
// Remove window from global object to simulate SSR environment
vi.stubGlobal("window", undefined);
Expand Down
Loading