修正启动检查系统变体用例的负向断言竞态

- 先等系统变体经 unhandledrejection 抛出(并校验抛出物带 Rust 原文),再断言登录页没有该文案
- 原写法在首个 waitFor tick 就因 queryByText 返回 null 而通过,没真正验证拒绝落地后的文案
This commit is contained in:
2026-10-01 21:12:45 +08:00
parent ce54c729e8
commit 08b8d0d167
@@ -271,6 +271,11 @@ export function registerAuthTests() {
it('keeps transport details out of the login copy by throwing system variants through', async () => {
const uninstall = installUnhandledRejectionBridge();
const reasons: unknown[] = [];
const onRejection = (event: Event) => {
reasons.push((event as Event & { reason?: unknown }).reason);
};
window.addEventListener('unhandledrejection', onRejection);
try {
const invoke = vi.fn(async (command: string) => {
if (command === 'read_client_auth_state') {
@@ -287,12 +292,16 @@ export function registerAuthTests() {
renderAuthSurface(invoke);
await loginWithCode();
await waitFor(() =>
expect(screen.queryByText(/无法连接登录服务/u)).toBeNull(),
);
// 先等系统变体真的经 unhandledrejection 抛出,再断言它没落到登录页文案。
await waitFor(() => expect(reasons).toHaveLength(1));
expect(reasons[0]).toMatchObject({
message: '无法连接登录服务,请确认配套后端或 API 代理已启动后重试',
});
expect(screen.queryByText(/无法连接登录服务/u)).toBeNull();
expect(document.body.textContent).not.toContain('ECONNREFUSED');
await screen.findByRole('main', { name: '登录' });
} finally {
window.removeEventListener('unhandledrejection', onRejection);
uninstall();
}
});