Files
Genarrative/apps/ai-game-creator-shell/tests/clientRuntimeErrorBoundary.test.ts
T
k88936 594063a1e0 测试:修正 AGC 测试文件的类型错误
- 按 vitest 0.34 的参数元组口径改写 mock 泛型
- 修正 noUncheckedIndexedAccess 下的下标访问
- 补齐与当前类型脱节的测试桩字段
- 按 scripts/*.mjs 的运行时契约补局部类型声明
2026-10-03 17:41:30 +08:00

39 lines
1.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/** @vitest-environment jsdom */
import { fireEvent, render, screen } from '@testing-library/react';
import { createElement, type ReactNode } from 'react';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { ClientRuntimeErrorBoundary } from '../src/app/AuthenticatedClient';
// 该组件永远抛错,声明 ReactNode 返回类型才能作为 children 传给错误边界。
function BrokenAuthenticatedContent(): ReactNode {
throw new Error('首页渲染失败');
}
describe('AGC authenticated client error boundary', () => {
afterEach(() => {
vi.restoreAllMocks();
});
it('replaces a render crash with a recoverable login action', () => {
vi.spyOn(console, 'error').mockImplementation(() => undefined);
const onLogout = vi.fn();
render(
createElement(ClientRuntimeErrorBoundary, {
onLogout,
// `children` 是必填 prop(createElement 第三参不再满足必填 props 约束)。
children: createElement(BrokenAuthenticatedContent),
}),
);
expect(
screen.getByRole('main', { name: '客户端页面加载失败' }),
).toBeTruthy();
expect(screen.getByText('首页渲染失败')).toBeTruthy();
fireEvent.click(screen.getByRole('button', { name: '返回登录' }));
expect(onLogout).toHaveBeenCalledTimes(1);
});
});