import { ReactNode } from 'react'; import { MemoryRouter, Routes, Route, useLocation } from 'react-router-dom'; import { vi } from 'vitest'; /** * 测试路由器的包装组件 */ export function TestRouter({ children, initialPath = '/', routes = [] }: { children: ReactNode; initialPath?: string; routes?: Array<{ path: string; element: ReactNode }>; }) { return ( {routes.map((route, index) => ( // @ts-ignore ))} {/* @ts-ignore */} ); } /** * 获取当前路由位置的Hook */ export function useTestLocation() { const location = useLocation(); return location; } /** * 创建测试导航函数 */ export function createTestNavigation() { return { navigate: vi.fn(), goBack: vi.fn(), goForward: vi.fn(), replace: vi.fn() }; }