muyu-portal/test/smoke.tsx
2026-06-15 19:47:45 +09:00

26 lines
982 B
TypeScript

import { it, expect } from 'vitest';
import { render, act, cleanup } from '@testing-library/react';
import type { ComponentType } from 'react';
/**
* Smoke test for a routed page entry: render it with its `@umijs/max` and
* `@/services/api` dependencies mocked, flush the async data fetches that
* pages kick off on mount, and assert it mounted without throwing. A render
* error (or an error thrown from a settled effect) fails the test.
*
* Each page test file calls this so every frontend entry has its own case.
*/
export function smokeTest(Page: ComponentType<any>) {
it('mounts without crashing', async () => {
const { container } = render(<Page />);
// Let the mocked API promises resolve and their state updates apply
// inside act(), so pages that fetch on mount settle cleanly.
await act(async () => {
await Promise.resolve();
await Promise.resolve();
});
expect(container).toBeInstanceOf(HTMLElement);
cleanup();
});
}