/** @jsx jsx */ /** @jsxImportSource hono/jsx */ /** @jsxFrag */ import { expect, test } from "vitest"; import { toReactNode } from "./toReactNode.js"; test("primitive", () => { expect(toReactNode("hello")).toMatchInlineSnapshot(` "hello" `); expect(toReactNode(1)).toMatchInlineSnapshot("1"); expect(toReactNode([1, "hello"])).toMatchInlineSnapshot(` [ 1, "hello", ] `); }); test("empty", () => { expect(toReactNode(
)).toMatchInlineSnapshot(` { "key": null, "props": { "children": [], }, "type": "div", } `); }); test("children", () => { expect(toReactNode(
hello
)).toMatchInlineSnapshot(` { "key": null, "props": { "children": "hello", }, "type": "div", } `); }); test("JSX children", () => { expect( toReactNode(
hello
world
{69}
, ), ).toMatchInlineSnapshot(` { "key": null, "props": { "children": [ { "key": null, "props": { "children": "hello", }, "type": "div", }, { "key": null, "props": { "children": "world", }, "type": "div", }, { "key": null, "props": { "children": 69, }, "type": "div", }, ], }, "type": "div", } `); }); test("fragment", () => { expect( toReactNode(
<>
hello
world
, ), ).toMatchInlineSnapshot(` { "key": null, "props": { "children": [ { "key": null, "props": { "children": "hello", }, "type": "div", }, { "key": null, "props": { "children": "world", }, "type": "div", }, ], }, "type": "div", } `); }); test("array", () => { expect( toReactNode([
hello
,
world
]), ).toMatchInlineSnapshot(` [ { "key": null, "props": { "children": "hello", }, "type": "div", }, { "key": null, "props": { "children": "world", }, "type": "div", }, ] `); }); test("props", () => { expect( toReactNode(
ok
, ), ).toMatchInlineSnapshot(` { "key": null, "props": { "baz": { "barry": true, }, "children": "ok", "className": "lol", "foo": "bar", "style": { "backgroundColor": "red", }, }, "type": "div", } `); }); test("component", () => { function Test() { return (
ok
); } expect(toReactNode()).toMatchInlineSnapshot(` { "key": null, "props": { "baz": { "barry": true, }, "children": "ok", "className": "lol", "foo": "bar", "style": { "backgroundColor": "red", }, }, "type": "div", } `); }); test("component w/ children + props", () => { function Test({ children, style, }: { children: JSX.Element[]; style: object }) { return (
{children}
); } expect( toReactNode(
hello world
this is me
, ), ).toMatchInlineSnapshot(` { "key": null, "props": { "baz": { "barry": true, }, "children": [ { "key": null, "props": { "children": "hello world", "style": { "backgroundColor": "blue", }, }, "type": "div", }, { "key": null, "props": { "children": "this is me", "style": { "backgroundColor": "blue", }, }, "type": "div", }, ], "className": "lol", "foo": "bar", "style": { "backgroundColor": "red", }, }, "type": "div", } `); });