From c358acd11b4ce6243a767681d12730452a6a954b Mon Sep 17 00:00:00 2001 From: supdger Date: Sat, 28 Nov 2026 00:54:19 -0800 Subject: [PATCH] =?UTF-8?q?test(web):=20DeptsPage=20=E7=AD=89=20Semi=20?= =?UTF-8?q?=E6=B5=AE=E5=B1=82=E5=BC=82=E6=AD=A5=E9=93=BE=E8=B5=B0=E5=AE=8C?= =?UTF-8?q?=E5=86=8D=E7=BB=93=E6=9D=9F=EF=BC=8C=E4=BF=AE=E5=81=B6=E5=8F=91?= =?UTF-8?q?=20unhandled=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 「更多」下拉是 Semi Tooltip(trigger=click) 受控浮层:点击后 insertPortal 先离屏插入,jsdom 无布局且 ResizeObserver 是空桩,portalInserted 只能靠 100ms 安全网定时器触发,随后 calcPosition → positionUpdated → 可见,整条 链跨多个宏任务。原测试断言完即结束,链路常在卸载后才继续触发,偶发在 React/jsdom 内部抛 unhandled error(CI 记录 nodeType of null)判红整个文件。 aria-expanded 在 notifyVisibleChange 之后才翻成 true,是链路最末端信号; 等到它即保证挂起定时器全部在挂载状态下耗尽(实测 aria-expanded 翻 true 后 400ms 内 DOM 零 mutation)。不加测试重试、不跳过用例、不放宽断言。 验证:目标测试连跑 50 次全绿;typecheck/lint/全量 vitest(536 passed)/ playwright smoke 均通过。 --- web/src/pages/org/depts/DeptsPage.test.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/web/src/pages/org/depts/DeptsPage.test.tsx b/web/src/pages/org/depts/DeptsPage.test.tsx index 7a5cf518..6cd37c83 100644 --- a/web/src/pages/org/depts/DeptsPage.test.tsx +++ b/web/src/pages/org/depts/DeptsPage.test.tsx @@ -1,7 +1,7 @@ import '@douyinfe/semi-ui/react19-adapter'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; -import { render, screen, within } from '@testing-library/react'; +import { render, screen, waitFor, within } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { MemoryRouter } from 'react-router'; import { afterEach, describe, expect, it } from 'vitest'; @@ -63,6 +63,15 @@ describe('DeptsPage', () => { await userEvent.click(within(row as HTMLElement).getByRole('button', { name: '更多' })); const remove = await screen.findByText('删除'); expect(remove.closest('[aria-disabled="true"]')).not.toBeNull(); + // 浮层「插入 → 定位 → 可见」靠 insertPortal 的 100ms 安全网定时器推进(jsdom 无布局、 + // ResizeObserver 空桩);链路未走完就结束测试,卸载后挂起定时器仍触发,偶发抛 unhandled + // error(CI 记录 nodeType of null)。aria-expanded 是链路最末端信号,等到它即耗尽挂起定时器。 + await waitFor(() => { + expect(within(row as HTMLElement).getByRole('button', { name: '更多' })).toHaveAttribute( + 'aria-expanded', + 'true', + ); + }); }); it('hides write controls for view-only accounts', async () => {