Skip to content

Commit a4a0bfe

Browse files
committed
Mock Lucide icons globally
1 parent f41c7db commit a4a0bfe

File tree

6 files changed

+21
-63
lines changed

6 files changed

+21
-63
lines changed

webview-ui/jest.config.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.exports = {
66
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
77
transform: { "^.+\\.(ts|tsx)$": ["ts-jest", { tsconfig: { jsx: "react-jsx", module: "ESNext" } }] },
88
testMatch: ["<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}", "<rootDir>/src/**/*.{spec,test}.{js,jsx,ts,tsx}"],
9-
setupFilesAfterEnv: ["<rootDir>/src/setupTests.ts"],
9+
setupFilesAfterEnv: ["<rootDir>/src/setupTests.tsx"],
1010
moduleNameMapper: {
1111
"\\.(css|less|scss|sass)$": "identity-obj-proxy",
1212
"^vscrui$": "<rootDir>/src/__mocks__/vscrui.ts",

webview-ui/src/components/common/__tests__/CodeBlock.test.tsx

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,6 @@ jest.mock("shiki", () => ({
2828
},
2929
}))
3030

31-
// Mock all lucide-react icons with a proxy to handle any icon requested
32-
jest.mock("lucide-react", () => {
33-
return new Proxy(
34-
{},
35-
{
36-
get: function (_obj, prop) {
37-
// Return a component factory for any icon that's requested
38-
if (prop === "__esModule") {
39-
return true
40-
}
41-
return () => <div data-testid={`${String(prop)}-icon`}>{String(prop)}</div>
42-
},
43-
},
44-
)
45-
})
46-
4731
// Mock the highlighter utility
4832
jest.mock("../../../utils/highlighter", () => {
4933
const mockHighlighter = {

webview-ui/src/components/modes/__tests__/ModesView.test.tsx

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,6 @@ jest.mock("@src/utils/vscode", () => ({
1212
},
1313
}))
1414

15-
// Mock all lucide-react icons with a proxy to handle any icon requested
16-
jest.mock("lucide-react", () => {
17-
return new Proxy(
18-
{},
19-
{
20-
get: function (_obj, prop) {
21-
// Return a component factory for any icon that's requested
22-
if (prop === "__esModule") {
23-
return true
24-
}
25-
return () => <div data-testid={`${String(prop)}-icon`}>{String(prop)}</div>
26-
},
27-
},
28-
)
29-
})
30-
3115
const mockExtensionState = {
3216
customModePrompts: {},
3317
listApiConfigMeta: [

webview-ui/src/components/settings/__tests__/ContextManagementSettings.test.tsx

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,6 @@ class MockResizeObserver {
1313

1414
global.ResizeObserver = MockResizeObserver
1515

16-
// Mock lucide-react icons - these don't work well in Jest/JSDOM environment
17-
jest.mock("lucide-react", () => {
18-
return {
19-
Database: React.forwardRef((props: any, ref: any) => <div ref={ref} data-testid="database-icon" {...props} />),
20-
ChevronDown: React.forwardRef((props: any, ref: any) => (
21-
<div ref={ref} data-testid="chevron-down-icon" {...props} />
22-
)),
23-
ChevronUp: React.forwardRef((props: any, ref: any) => (
24-
<div ref={ref} data-testid="chevron-up-icon" {...props} />
25-
)),
26-
Check: React.forwardRef((props: any, ref: any) => <div ref={ref} data-testid="check-icon" {...props} />),
27-
}
28-
})
29-
3016
// Mock translation hook to return the key as the translation
3117
jest.mock("@/i18n/TranslationContext", () => ({
3218
useAppTranslation: () => ({

webview-ui/src/components/settings/__tests__/SettingsView.test.tsx

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,6 @@ import SettingsView from "../SettingsView"
1010
// Mock vscode API
1111
jest.mock("@src/utils/vscode", () => ({ vscode: { postMessage: jest.fn() } }))
1212

13-
// Mock all lucide-react icons with a proxy to handle any icon requested
14-
jest.mock("lucide-react", () => {
15-
return new Proxy(
16-
{},
17-
{
18-
get: function (_obj, prop) {
19-
// Return a component factory for any icon that's requested
20-
if (prop === "__esModule") {
21-
return true
22-
}
23-
return () => <div data-testid={`${String(prop)}-icon`}>{String(prop)}</div>
24-
},
25-
},
26-
)
27-
})
28-
2913
// Mock ApiConfigManager component
3014
jest.mock("../ApiConfigManager", () => ({
3115
__esModule: true,

webview-ui/src/setupTests.ts renamed to webview-ui/src/setupTests.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,23 @@ Object.defineProperty(window, "matchMedia", {
3030
dispatchEvent: jest.fn(),
3131
})),
3232
})
33+
34+
// Mock lucide-react icons globally using Proxy for dynamic icon handling
35+
jest.mock("lucide-react", () => {
36+
return new Proxy(
37+
{},
38+
{
39+
get: function (_obj, prop) {
40+
// Return a component factory for any icon that's requested
41+
if (prop === "__esModule") {
42+
return true
43+
}
44+
return (props: any) => (
45+
<div {...props} data-testid={`${String(prop)}-icon`}>
46+
{String(prop)}
47+
</div>
48+
)
49+
},
50+
},
51+
)
52+
})

0 commit comments

Comments
 (0)