Skip to content
Closed
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
12 changes: 12 additions & 0 deletions src/lib/__tests__/cardSettings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,18 @@ describe("cardSettings", () => {
expect(profileBlock).toBeDefined();
});


it("safely handles exceptions when accessing localStorage (e.g. security error)", () => {
getItemMock.mockImplementation(() => {
throw new Error("SecurityError: localStorage is restricted");
});

const result = loadCardSettings();

expect(result.layout).toEqual(DEFAULT_CARD_LAYOUT);
expect(result.options).toEqual(getDefaultCardSettings().options);
});

Comment on lines 156 to +168

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

The newly added test is currently indented with 8 spaces, which visually suggests it is nested inside the describe("loadCardSettings") block. However, that block was closed earlier at line 124. As a result, this test is actually a direct child of describe("cardSettings").

To maintain consistent formatting and prevent confusion about the test hierarchy, we should adjust its indentation to 4 spaces and remove the extra blank line before the test. Additionally, ensure that functions and mock implementations have explicit return types to maintain type safety and readability.

    it("safely handles exceptions when accessing localStorage (e.g. security error)", (): void => {
        getItemMock.mockImplementation((): never => {
            throw new Error("SecurityError: localStorage is restricted");
        });

        const result = loadCardSettings();

        expect(result.layout).toEqual(DEFAULT_CARD_LAYOUT);
        expect(result.options).toEqual(getDefaultCardSettings().options);
    });
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.

describe("saveCardSettings", () => {
it("does nothing when window is undefined", () => {
vi.stubGlobal("window", undefined);
Expand Down
Loading