Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/main.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { z } from 'zod';

import { installZodKorean } from '@/shared/lib/zod-locale';

const { createRoot, render } = vi.hoisted(() => {
const render = vi.fn();
return { render, createRoot: vi.fn(() => ({ render })) };
});
vi.mock('react-dom/client', () => ({ createRoot }));

const emptyMessage = () => z.string().min(1).safeParse('').error?.issues[0]?.message;

/** 테스트 setup도 한국어 문구를 설치하므로, main.tsx에서 설치가 빠져도 다른 spec은 모른다. */
describe('앱 부팅(main.tsx)', () => {
afterEach(() => {
installZodKorean();
document.getElementById('root')?.remove();
});

it('zod 한국어 문구를 설치하고 #root에 앱을 한 번 렌더한다', async () => {
z.config({ ...z.locales.en(), customError: undefined });
expect(emptyMessage()).not.toBe('값을 입력해 주세요.');
const root = document.createElement('div');
root.id = 'root';
document.body.append(root);

await import('./main');

expect(emptyMessage()).toBe('값을 입력해 주세요.');
expect(createRoot).toHaveBeenCalledWith(root);
expect(render).toHaveBeenCalledTimes(1);
});
});
Loading