pegasus/frontend/src/main.test.tsx

41 lines
1008 B
TypeScript
Raw Normal View History

import { beforeEach, describe, expect, it, jest } from '@jest/globals'
2026-04-11 00:02:59 -03:00
const mockRender = jest.fn()
const mockCreateRoot = jest.fn(() => ({ render: mockRender }))
2026-04-11 00:02:59 -03:00
jest.mock('react-dom/client', () => ({
createRoot: mockCreateRoot,
2026-04-11 00:02:59 -03:00
}))
jest.mock('./App', () => function MockApp() {
return null
})
2026-04-11 00:02:59 -03:00
describe('main entrypoint', () => {
beforeEach(() => {
jest.resetModules()
2026-04-11 00:02:59 -03:00
document.body.innerHTML = '<div id="root"></div>'
mockCreateRoot.mockClear()
mockRender.mockClear()
2026-04-11 00:02:59 -03:00
})
it('mounts the app into #root', async () => {
await jest.isolateModulesAsync(async () => {
await import('./main')
})
2026-04-11 00:02:59 -03:00
expect(mockCreateRoot).toHaveBeenCalled()
expect(mockRender).toHaveBeenCalled()
2026-04-11 00:02:59 -03:00
})
it('fails fast when the root node is missing', async () => {
document.body.innerHTML = ''
await expect(
jest.isolateModulesAsync(async () => {
await import('./main')
}),
).rejects.toThrow('Missing <div id="root"></div> in index.html')
2026-04-11 00:02:59 -03:00
})
})