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

// Mock fast-average-color
interface MockFastAverageColor {
getColorAsync: ReturnType<typeof vi.fn>;
destroy: ReturnType<typeof vi.fn>;
}
vi.mock("fast-average-color", () => {
const mockGetColorAsync = vi.fn();
const mockDestroy = vi.fn();
return {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
FastAverageColor: vi.fn().mockImplementation(function(this: any) {
FastAverageColor: vi.fn().mockImplementation(function(this: MockFastAverageColor) {
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

In TypeScript, ensure functions and mock implementations have explicit return types to maintain type safety and readability. Adding the return type to the mock implementation function ensures consistency and better type checking.

Suggested change
FastAverageColor: vi.fn().mockImplementation(function(this: MockFastAverageColor) {
FastAverageColor: vi.fn().mockImplementation(function(this: MockFastAverageColor): MockFastAverageColor {
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.
  2. Maintain explicit return types for functions in TypeScript to ensure type safety and API clarity.

this.getColorAsync = mockGetColorAsync;
this.destroy = mockDestroy;
return this;
Expand Down
Loading