11import { describe , it } from "jsr:@std/testing@^1/bdd" ;
22import { expect } from "jsr:@std/expect@^1" ;
33import { h } from "npm:hastscript@9.0.0" ;
4+ import type { JSXChild , JSXChildren } from "../jsx-runtime.ts" ;
45
56describe ( "JSX runtime" , ( ) => {
67 it ( "generates simple tags" , ( ) => {
@@ -60,9 +61,24 @@ describe("JSX runtime", () => {
6061 ) ;
6162 } ) ;
6263
63- it ( "can embed boolean expressions inside" , ( ) => {
64+ it ( "ignores boolean expressions inside" , ( ) => {
6465 expect ( < title > { false } witness</ title > ) . toEqual (
65- h ( "title" , "false" , " witness" ) ,
66+ h ( "title" , " witness" ) ,
67+ ) ;
68+ expect ( < title > { true } love</ title > ) . toEqual (
69+ h ( "title" , " love" ) ,
70+ ) ;
71+ } ) ;
72+
73+ it ( "ignores undefined" , ( ) => {
74+ expect ( < title > { undefined } behavior</ title > ) . toEqual (
75+ h ( "title" , " behavior" ) ,
76+ ) ;
77+ } ) ;
78+
79+ it ( "ignores null" , ( ) => {
80+ expect ( < title > { null } hypothesis</ title > ) . toEqual (
81+ h ( "title" , " hypothesis" ) ,
6682 ) ;
6783 } ) ;
6884
@@ -89,6 +105,12 @@ describe("JSX runtime", () => {
89105 expect ( < ul > { ...[ 1 , 2 , 3 ] . map ( ( i ) => < li > { i } </ li > ) } </ ul > ) . toEqual (
90106 h ( "ul" , h ( "li" , "1" ) , h ( "li" , "2" ) , h ( "li" , "3" ) ) ,
91107 ) ;
108+ expect (
109+ < ul >
110+ < li > 0</ li >
111+ { ...[ 1 , 2 , 3 ] . map ( ( i ) => < li > { i } </ li > ) }
112+ </ ul > ,
113+ ) . toEqual ( h ( "ul" , h ( "li" , "0" ) , h ( "li" , "1" ) , h ( "li" , "2" ) , h ( "li" , "3" ) ) ) ;
92114 } ) ;
93115
94116 it ( "passes the key attribute" , ( ) => {
@@ -114,4 +136,17 @@ describe("JSX runtime", () => {
114136 //@ts -expect-error yo.
115137 expect ( el . properties . className ) . toEqual ( "button" ) ;
116138 } ) ;
139+
140+ it ( "strips <!DOCTYPE> from element children" , ( ) => {
141+ const root : JSXChild = { type : "root" , children : [ { type : "doctype" } ] } ;
142+ expect ( < > { root } </ > ) . toEqual ( root ) ;
143+ expect ( < div > { root } </ div > ) . toEqual ( h ( "div" ) ) ;
144+ } ) ;
145+
146+ it ( "allows components returning primitives or arrays" , ( ) => {
147+ const Id = ( { children } : { children ?: JSXChildren } ) => children ;
148+ expect ( < Id /> ) . toEqual ( < > </ > ) ;
149+ expect ( < Id > { 1 } </ Id > ) . toEqual ( < > { 1 } </ > ) ;
150+ expect ( < Id > s { 1 } </ Id > ) . toEqual ( < > s { 1 } </ > ) ;
151+ } ) ;
117152} ) ;
0 commit comments