11import { beforeEach , describe , expect , test } from "bun:test" ;
2+ import { Fragment , jsx , jsxDEV , jsxs , render , useState } from "@/MiniReact" ;
3+ import type { FunctionalComponent , MiniReactElement } from "@/core/types" ;
24import { Window } from "happy-dom" ;
3- import {
4- Fragment ,
5- jsx ,
6- jsxDEV ,
7- jsxs ,
8- render ,
9- useState ,
10- } from "../src/MiniReact" ;
11- import type { FunctionalComponent , MiniReactElement } from "../src/core/types" ;
125
136let window : Window ;
147let document : Document ;
@@ -30,7 +23,7 @@ describe("JSX Runtime Functions", () => {
3023 const element = jsx ( "div" , { id : "test" } ) as MiniReactElement ;
3124
3225 expect ( element . type ) . toBe ( "div" ) ;
33- expect ( ( element . props as Record < string , unknown > ) . id ) . toBe ( "test" ) ;
26+ expect ( ( element . props as Record < string , unknown > ) [ "id" ] ) . toBe ( "test" ) ;
3427 expect ( element . props . children ) . toEqual ( [ ] ) ;
3528 } ) ;
3629
@@ -52,8 +45,8 @@ describe("JSX Runtime Functions", () => {
5245 test ( "jsx() handles key prop" , ( ) => {
5346 const element = jsx ( "div" , { id : "test" } , "my-key" ) as MiniReactElement ;
5447
55- expect ( ( element . props as Record < string , unknown > ) . key ) . toBe ( "my-key" ) ;
56- expect ( ( element . props as Record < string , unknown > ) . id ) . toBe ( "test" ) ;
48+ expect ( ( element . props as Record < string , unknown > ) [ " key" ] ) . toBe ( "my-key" ) ;
49+ expect ( ( element . props as Record < string , unknown > ) [ "id" ] ) . toBe ( "test" ) ;
5750 } ) ;
5851
5952 test ( "jsxs() works identically to jsx()" , ( ) => {
@@ -75,13 +68,13 @@ describe("JSX Runtime Functions", () => {
7568 ) ;
7669
7770 expect ( element . type ) . toBe ( "div" ) ;
78- expect ( ( element . props as Record < string , unknown > ) . id ) . toBe ( "test" ) ;
79- expect ( ( element . props as Record < string , unknown > ) . key ) . toBe ( "key" ) ;
71+ expect ( ( element . props as Record < string , unknown > ) [ "id" ] ) . toBe ( "test" ) ;
72+ expect ( ( element . props as Record < string , unknown > ) [ " key" ] ) . toBe ( "key" ) ;
8073
8174 // Test that jsxDEV creates similar structure
8275 expect ( elementWithSource . type ) . toBe ( "div" ) ;
8376 expect (
84- ( elementWithSource as unknown as Record < string , unknown > ) . __source ,
77+ ( elementWithSource as unknown as Record < string , unknown > ) [ " __source" ] ,
8578 ) . toEqual ( source ) ;
8679 } ) ;
8780
@@ -133,10 +126,10 @@ describe("JSX Fragment Support", () => {
133126 render ( fragmentElement , container ) ;
134127
135128 expect ( container . children . length ) . toBe ( 2 ) ;
136- expect ( container . children [ 0 ] . tagName ) . toBe ( "SPAN" ) ;
137- expect ( container . children [ 0 ] . textContent ) . toBe ( "Hello" ) ;
138- expect ( container . children [ 1 ] . tagName ) . toBe ( "SPAN" ) ;
139- expect ( container . children [ 1 ] . textContent ) . toBe ( "World" ) ;
129+ expect ( container . children [ 0 ] ! . tagName ) . toBe ( "SPAN" ) ;
130+ expect ( container . children [ 0 ] ! . textContent ) . toBe ( "Hello" ) ;
131+ expect ( container . children [ 1 ] ! . tagName ) . toBe ( "SPAN" ) ;
132+ expect ( container . children [ 1 ] ! . textContent ) . toBe ( "World" ) ;
140133 } ) ;
141134
142135 test ( "Fragment with single child" , ( ) => {
@@ -147,8 +140,8 @@ describe("JSX Fragment Support", () => {
147140 render ( fragmentElement , container ) ;
148141
149142 expect ( container . children . length ) . toBe ( 1 ) ;
150- expect ( container . children [ 0 ] . tagName ) . toBe ( "DIV" ) ;
151- expect ( container . children [ 0 ] . textContent ) . toBe ( "Single child" ) ;
143+ expect ( container . children [ 0 ] ! . tagName ) . toBe ( "DIV" ) ;
144+ expect ( container . children [ 0 ] ! . textContent ) . toBe ( "Single child" ) ;
152145 } ) ;
153146
154147 test ( "Fragment with no children" , ( ) => {
@@ -168,9 +161,9 @@ describe("JSX Fragment Support", () => {
168161 render ( fragmentElement , container ) ;
169162
170163 expect ( container . childNodes . length ) . toBe ( 3 ) ;
171- expect ( container . childNodes [ 0 ] . textContent ) . toBe ( "Text node" ) ;
172- expect ( container . childNodes [ 1 ] . textContent ) . toBe ( "Element" ) ;
173- expect ( container . childNodes [ 2 ] . textContent ) . toBe ( "42" ) ;
164+ expect ( container . childNodes [ 0 ] ! . textContent ) . toBe ( "Text node" ) ;
165+ expect ( container . childNodes [ 1 ] ! . textContent ) . toBe ( "Element" ) ;
166+ expect ( container . childNodes [ 2 ] ! . textContent ) . toBe ( "42" ) ;
174167 } ) ;
175168} ) ;
176169
@@ -185,8 +178,8 @@ describe("JSX with Functional Components", () => {
185178 render ( element , container ) ;
186179
187180 expect ( container . children . length ) . toBe ( 1 ) ;
188- expect ( container . children [ 0 ] . tagName ) . toBe ( "H1" ) ;
189- expect ( container . children [ 0 ] . textContent ) . toBe ( "Hello, JSX!" ) ;
181+ expect ( container . children [ 0 ] ! . tagName ) . toBe ( "H1" ) ;
182+ expect ( container . children [ 0 ] ! . textContent ) . toBe ( "Hello, JSX!" ) ;
190183 } ) ;
191184
192185 test ( "jsx() with component children" , ( ) => {
@@ -201,8 +194,8 @@ describe("JSX with Functional Components", () => {
201194 render ( jsx ( App , null ) , container ) ;
202195
203196 expect ( container . children . length ) . toBe ( 1 ) ;
204- expect ( container . children [ 0 ] . tagName ) . toBe ( "BUTTON" ) ;
205- expect ( container . children [ 0 ] . textContent ) . toBe ( "Click me" ) ;
197+ expect ( container . children [ 0 ] ! . tagName ) . toBe ( "BUTTON" ) ;
198+ expect ( container . children [ 0 ] ! . textContent ) . toBe ( "Click me" ) ;
206199 } ) ;
207200
208201 test ( "jsx() with nested components" , ( ) => {
@@ -228,14 +221,14 @@ describe("JSX with Functional Components", () => {
228221
229222 render ( app , container ) ;
230223
231- const card = container . children [ 0 ] as HTMLElement ;
224+ const card = container . children [ 0 ] ! as HTMLElement ;
232225 expect ( card . className ) . toBe ( "card" ) ;
233226 expect ( card . children . length ) . toBe ( 2 ) ;
234- expect ( card . children [ 0 ] . tagName ) . toBe ( "H2" ) ;
235- expect ( card . children [ 0 ] . textContent ) . toBe ( "My Card" ) ;
236- expect ( card . children [ 1 ] . className ) . toBe ( "content" ) ;
237- expect ( card . children [ 1 ] . children [ 0 ] . tagName ) . toBe ( "P" ) ;
238- expect ( card . children [ 1 ] . children [ 0 ] . textContent ) . toBe ( "Card content" ) ;
227+ expect ( card . children [ 0 ] ! . tagName ) . toBe ( "H2" ) ;
228+ expect ( card . children [ 0 ] ! . textContent ) . toBe ( "My Card" ) ;
229+ expect ( card . children [ 1 ] ! . className ) . toBe ( "content" ) ;
230+ expect ( card . children [ 1 ] ! . children [ 0 ] ! . tagName ) . toBe ( "P" ) ;
231+ expect ( card . children [ 1 ] ! . children [ 0 ] ! . textContent ) . toBe ( "Card content" ) ;
239232 } ) ;
240233} ) ;
241234
@@ -291,10 +284,10 @@ describe("JSX with Hooks", () => {
291284
292285 render ( jsx ( MultiState , null ) , container ) ;
293286
294- const nameP = container . children [ 0 ] . children [ 0 ] as HTMLElement ;
295- const ageP = container . children [ 0 ] . children [ 1 ] as HTMLElement ;
296- const nameButton = container . children [ 0 ] . children [ 2 ] as HTMLElement ;
297- const ageButton = container . children [ 0 ] . children [ 3 ] as HTMLElement ;
287+ const nameP = container . children [ 0 ] ! . children [ 0 ] ! as HTMLElement ;
288+ const ageP = container . children [ 0 ] ! . children [ 1 ] ! as HTMLElement ;
289+ const nameButton = container . children [ 0 ] ! . children [ 2 ] ! as HTMLElement ;
290+ const ageButton = container . children [ 0 ] ! . children [ 3 ] ! as HTMLElement ;
298291
299292 expect ( nameP . textContent ) . toBe ( "Name: Anonymous" ) ;
300293 expect ( ageP . textContent ) . toBe ( "Age: 0" ) ;
@@ -368,7 +361,7 @@ describe("JSX Error Handling", () => {
368361 render ( element , container ) ;
369362
370363 expect ( container . children . length ) . toBe ( 1 ) ;
371- expect ( container . children [ 0 ] . textContent ) . toBe ( "text" ) ;
364+ expect ( container . children [ 0 ] ! . textContent ) . toBe ( "text" ) ;
372365 } ) ;
373366
374367 test ( "jsx() handles empty children array" , ( ) => {
@@ -377,7 +370,7 @@ describe("JSX Error Handling", () => {
377370 render ( element , container ) ;
378371
379372 expect ( container . children . length ) . toBe ( 1 ) ;
380- expect ( container . children [ 0 ] . children . length ) . toBe ( 0 ) ;
373+ expect ( container . children [ 0 ] ! . children . length ) . toBe ( 0 ) ;
381374 } ) ;
382375
383376 test ( "jsx() handles component returning null" , ( ) => {
@@ -402,9 +395,9 @@ describe("JSX Performance and Edge Cases", () => {
402395 render ( element , container ) ;
403396
404397 expect ( container . children . length ) . toBe ( 1 ) ;
405- expect ( container . children [ 0 ] . children . length ) . toBe ( 100 ) ;
406- expect ( container . children [ 0 ] . children [ 0 ] . textContent ) . toBe ( "Item 0" ) ;
407- expect ( container . children [ 0 ] . children [ 99 ] . textContent ) . toBe ( "Item 99" ) ;
398+ expect ( container . children [ 0 ] ! . children . length ) . toBe ( 100 ) ;
399+ expect ( container . children [ 0 ] ! . children [ 0 ] ! . textContent ) . toBe ( "Item 0" ) ;
400+ expect ( container . children [ 0 ] ! . children [ 99 ] ! . textContent ) . toBe ( "Item 99" ) ;
408401 } ) ;
409402
410403 test ( "jsx() maintains referential equality for same inputs" , ( ) => {
@@ -415,8 +408,8 @@ describe("JSX Performance and Edge Cases", () => {
415408 // Elements should have the same structure but be different objects
416409 expect ( element1 ) . not . toBe ( element2 ) ;
417410 expect ( element1 . type ) . toBe ( element2 . type ) ;
418- expect ( ( element1 . props as Record < string , unknown > ) . id ) . toBe (
419- ( element2 . props as Record < string , unknown > ) . id ,
411+ expect ( ( element1 . props as Record < string , unknown > ) [ "id" ] ) . toBe (
412+ ( element2 . props as Record < string , unknown > ) [ "id" ] ,
420413 ) ;
421414 } ) ;
422415
@@ -425,9 +418,9 @@ describe("JSX Performance and Edge Cases", () => {
425418 const element = jsxDEV ( "div" , { id : "test" } , "key" , true , source , { } ) ;
426419
427420 expect ( element . type ) . toBe ( "div" ) ;
428- expect ( ( element . props as Record < string , unknown > ) . id ) . toBe ( "test" ) ;
429- expect ( ( element . props as Record < string , unknown > ) . key ) . toBe ( "key" ) ;
430- expect ( ( element as unknown as Record < string , unknown > ) . __source ) . toEqual (
421+ expect ( ( element . props as Record < string , unknown > ) [ "id" ] ) . toBe ( "test" ) ;
422+ expect ( ( element . props as Record < string , unknown > ) [ " key" ] ) . toBe ( "key" ) ;
423+ expect ( ( element as unknown as Record < string , unknown > ) [ " __source" ] ) . toEqual (
431424 source ,
432425 ) ;
433426 } ) ;
0 commit comments