11import React from 'react' ;
22import ReactDOM from 'react-dom/client' ;
3-
43jest . mock ( '../App.tsx' , ( ) => ( {
54 __esModule : true ,
65 default : ( ) => < div data-testid = "app" > App</ div > ,
@@ -12,37 +11,28 @@ jest.mock('@/components/utils/ThemeProvider.tsx', () => ({
1211 ) ,
1312} ) ) ;
1413
15- describe ( 'main.tsx' , ( ) => {
16- beforeEach ( ( ) => {
17- document . body . innerHTML = '<div id="root"></div>' ;
18- } ) ;
14+ describe ( 'main.tsx bootstrap' , ( ) => {
15+ const renderMock = jest . fn ( ) ;
1916
20- it ( 'has root element available for React app' , ( ) => {
21- const rootElement = document . getElementById ( 'root' ) ;
22- expect ( rootElement ) . toBeInTheDocument ( ) ;
23- expect ( rootElement ) . not . toBeNull ( ) ;
24- } ) ;
17+ beforeEach ( ( ) => {
18+ jest . spyOn ( ReactDOM , 'createRoot' ) . mockReturnValue ( {
19+ render : renderMock ,
20+ } as any ) ;
2521
26- it ( 'can create React root without errors' , ( ) => {
27- const rootElement = document . getElementById ( 'root' ) ;
28- expect ( ( ) => {
29- ReactDOM . createRoot ( rootElement ! ) ;
30- } ) . not . toThrow ( ) ;
22+ document . body . innerHTML = '<div id="root"></div>' ;
3123 } ) ;
3224
33- it ( 'imports required React dependencies' , ( ) => {
34- expect ( React ) . toBeDefined ( ) ;
35- expect ( ReactDOM ) . toBeDefined ( ) ;
36- expect ( React . StrictMode ) . toBeDefined ( ) ;
25+ afterEach ( ( ) => {
26+ jest . restoreAllMocks ( ) ;
27+ document . body . innerHTML = '' ;
3728 } ) ;
3829
39- it ( 'verifies App and ThemeProvider components are available' , ( ) => {
40- const App = require ( '../App.tsx' ) . default ;
41- const { ThemeProvider } = require ( '@/components/utils/ThemeProvider.tsx' ) ;
30+ it ( 'creates React root and renders the app' , async ( ) => {
31+ await import ( '../main.tsx' ) ;
4232
43- expect ( App ) . toBeDefined ( ) ;
44- expect ( ThemeProvider ) . toBeDefined ( ) ;
45- expect ( typeof App ) . toBe ( 'function' ) ;
46- expect ( typeof ThemeProvider ) . toBe ( 'function' ) ;
33+ expect ( ReactDOM . createRoot ) . toHaveBeenCalledWith (
34+ document . getElementById ( 'root' )
35+ ) ;
36+ expect ( renderMock ) . toHaveBeenCalled ( ) ;
4737 } ) ;
4838} ) ;
0 commit comments