From 7d2fbfa49fa22f4b9a5fdcfc5a405a6b30bd0630 Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Wed, 16 Sep 2026 06:46:48 +0800 Subject: [PATCH] =?UTF-8?q?fix(test):=20Header.test.tsx=20antd/icons=20moc?= =?UTF-8?q?k=20=E9=80=8F=E4=BC=A0=E7=BC=BA=E5=A4=B1=E5=AF=BC=E5=87=BA?= =?UTF-8?q?=EF=BC=88=E4=BF=AE=E5=A4=8D=20Typography=20=E6=9C=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=EF=BC=89=20(#1947)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: xiaoxia Co-committed-by: xiaoxia --- .../test/components/layout/Header.test.tsx | 89 +++++++++++-------- 1 file changed, 50 insertions(+), 39 deletions(-) diff --git a/apps/web/src/test/components/layout/Header.test.tsx b/apps/web/src/test/components/layout/Header.test.tsx index 6f7d7086a..fff71291b 100644 --- a/apps/web/src/test/components/layout/Header.test.tsx +++ b/apps/web/src/test/components/layout/Header.test.tsx @@ -45,49 +45,60 @@ vi.mock("@/config/navigation", () => ({ ], })) -// mock antd icons -vi.mock("@ant-design/icons", () => ({ - LogoutOutlined: () => , - SettingOutlined: () => , - UserOutlined: () => , - MenuOutlined: () => , -})) +// mock antd icons — 透传未显式 mock 的图标,避免 PointsBadge 等子组件引用新图标时报错 +vi.mock("@ant-design/icons", async () => { + const actual = (await vi.importActual( + "@ant-design/icons", + )) as Record + return { + ...actual, + LogoutOutlined: () => , + SettingOutlined: () => , + UserOutlined: () => , + MenuOutlined: () => , + } +}) -// mock antd components -vi.mock("antd", () => ({ - Avatar: ({ children, className }: any) => ( - - {children} - - ), - Dropdown: ({ children, menu }: any) => ( -
- {children} -
- {menu.items?.map((item: any, idx: number) => ( -
- {item.label} -
- ))} +// mock antd components — 用 importActual 透传未显式覆盖的组件(Popover/Button/Tag/Typography/Badge 等), +// 避免 Header 子组件(PointsBadge)使用新 antd 导出时出现 "No xxx export is defined on the antd mock" +vi.mock("antd", async () => { + const actual = (await vi.importActual("antd")) as Record + return { + ...actual, + Avatar: ({ children, className }: any) => ( + + {children} + + ), + Dropdown: ({ children, menu }: any) => ( +
+ {children} +
+ {menu.items?.map((item: any, idx: number) => ( +
+ {item.label} +
+ ))} +
-
- ), - Space: ({ children, className }: any) => ( -
- {children} -
- ), - Drawer: ({ title, open, children, onClose, placement }: any) => - open ? ( -
-
{title}
- + ), + Space: ({ children, className }: any) => ( +
{children}
- ) : null, -})) + ), + Drawer: ({ title, open, children, onClose, placement }: any) => + open ? ( +
+
{title}
+ + {children} +
+ ) : null, + } +}) // mock CSS vi.mock("@/components/layout/Header.css", () => ({}))