Skip to content
Open
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
9 changes: 5 additions & 4 deletions src/hooks/__tests__/useThemeColor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { renderHook, waitFor } from "@testing-library/react";
import { useThemeColor } from "../useThemeColor";
import * as colorLib from "@/lib/color";
import { FastAverageColor } from "fast-average-color";
import { logger } from "@/lib/logger";

// Mock fast-average-color
vi.mock("fast-average-color", () => {
Expand Down Expand Up @@ -54,8 +55,8 @@ describe("useThemeColor", () => {
value: [100, 150, 200, 255]
});

// Suppress console.warn for error tests
vi.spyOn(console, "warn").mockImplementation(() => {});
// Suppress logger.warn for error tests
vi.spyOn(logger, "warn").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

To maintain type safety and adhere to the repository's TypeScript guidelines, please provide an explicit return type for the mock implementation.

Suggested change
vi.spyOn(logger, "warn").mockImplementation(() => {});
vi.spyOn(logger, "warn").mockImplementation((): void => {});
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.

});

afterEach(() => {
Expand Down Expand Up @@ -124,9 +125,9 @@ describe("useThemeColor", () => {
expect(mockGetColorAsync).toHaveBeenCalled();
});

// Check that console.warn was called
// Check that logger.warn was called
await waitFor(() => {
expect(console.warn).toHaveBeenCalledWith(
expect(logger.warn).toHaveBeenCalledWith(
"Failed to extract color from avatar, keeping fallback color.",
error
);
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/useThemeColor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useEffect } from "react";
import { FastAverageColor } from "fast-average-color";
import { logger } from "@/lib/logger";
import { adjustAccentColor } from "@/lib/color";

function applyColor(color: string | [number, number, number]) {
Expand Down Expand Up @@ -47,7 +48,7 @@ export function useThemeColor({ avatarUrl, topLanguageColor }: UseThemeColorOpti
}
})
.catch((e) => {
console.warn("Failed to extract color from avatar, keeping fallback color.", e);
logger.warn("Failed to extract color from avatar, keeping fallback color.", e);
});
}

Expand Down
Loading