refactor: strengthen client boundaries and quality gates
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { RouteLoadBoundary } from './RouteLoadBoundary';
|
||||
|
||||
function BrokenRoute(): never {
|
||||
throw new Error('chunk load failed');
|
||||
}
|
||||
|
||||
describe('RouteLoadBoundary', () => {
|
||||
it('shows a recoverable Chinese error state when a route chunk throws', () => {
|
||||
vi.spyOn(console, 'error').mockImplementation(() => undefined);
|
||||
render(
|
||||
<RouteLoadBoundary>
|
||||
<BrokenRoute />
|
||||
</RouteLoadBoundary>,
|
||||
);
|
||||
expect(screen.getByRole('alert')).toHaveTextContent('页面资源加载失败');
|
||||
expect(screen.getByRole('button', { name: '重新加载' })).toBeEnabled();
|
||||
});
|
||||
|
||||
it('renders healthy route content unchanged', () => {
|
||||
render(
|
||||
<RouteLoadBoundary>
|
||||
<p>正常页面</p>
|
||||
</RouteLoadBoundary>,
|
||||
);
|
||||
expect(screen.getByText('正常页面')).toBeVisible();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user