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
Empty file added dummy.sh
Empty file.
7 changes: 4 additions & 3 deletions src/hooks/__tests__/useThemeColor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import { renderHook, waitFor } from "@testing-library/react";
import { useThemeColor } from "../useThemeColor";
import * as colorLib from "@/lib/color";
import { logger } from "@/lib/logger";
import { FastAverageColor } from "fast-average-color";

// 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

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 : void return type to the mock implementation function.

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.

Comment on lines 58 to +59

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 コメントが古い実装(console.warn)を参照しています。logger.warn をスパイしていることを正確に示すよう更新することを推奨します。

Suggested change
// Suppress console.warn for error tests
vi.spyOn(console, "warn").mockImplementation(() => {});
vi.spyOn(logger, "warn").mockImplementation(() => {});
// Suppress logger.warn for error tests
vi.spyOn(logger, "warn").mockImplementation(() => {});
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/hooks/__tests__/useThemeColor.test.ts
Line: 58-59

Comment:
コメントが古い実装(`console.warn`)を参照しています。`logger.warn` をスパイしていることを正確に示すよう更新することを推奨します。

```suggestion
    // Suppress logger.warn for error tests
    vi.spyOn(logger, "warn").mockImplementation(() => {});
```

How can I resolve this? If you propose a fix, please make it concise.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

});

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