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
5 changes: 3 additions & 2 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 @@ -55,7 +56,7 @@ describe("useThemeColor", () => {
});

// Suppress console.warn for error tests
vi.spyOn(console, "warn").mockImplementation(() => {});
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 adhere to the TypeScript guidelines, mock implementations should have explicit return types. Please add an explicit void return type to this 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 @@ -126,7 +127,7 @@ describe("useThemeColor", () => {

// Check that console.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,6 +1,7 @@
import { useEffect } from "react";
import { FastAverageColor } from "fast-average-color";
import { adjustAccentColor } from "@/lib/color";
import { logger } from "@/lib/logger";

function applyColor(color: string | [number, number, number]) {
const result = adjustAccentColor(color);
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