import { describe, expect, it } from 'vitest'; import { Fragment, jsx, jsxs, styleWire, type BdcElement } from './jsx-runtime'; describe('jsx-runtime', () => { it('creates an element from a string type', () => { const el = jsx('text', { text: 'hi' }); expect(el).toEqual({ type: 'text', props: { text: 'hi' }, children: [] }); }); it('flattens null, boolean, nested arrays, and text nodes', () => { const el = jsxs('column', null, null, false, true, 'hello', 42, [ jsx('text', { text: 'nested' }), [null, jsx('spacer', {})], ]); expect(el.children).toEqual([ { type: '_text_node', props: { value: 'hello' }, children: [] }, { type: '_text_node', props: { value: '42' }, children: [] }, { type: 'text', props: { text: 'nested' }, children: [] }, { type: 'spacer', props: {}, children: [] }, ]); }); it('merges children from props and rest args', () => { const child: BdcElement = { type: 'text', props: { text: 'a' }, children: [] }; const el = jsx('row', { gap: 8, children: child }, jsx('text', { text: 'b' })); expect(el.props).toEqual({ gap: 8 }); expect(el.children).toHaveLength(2); expect(el.children[0].props).toEqual({ text: 'a' }); expect(el.children[1].props).toEqual({ text: 'b' }); }); it('invokes function components', () => { const Comp = (props: Record) => ({ type: 'button', props: { label: props.label, children: props.children }, children: (props.children as BdcElement[]) ?? [], }); const el = jsx(Comp, { label: 'Go' }, jsx('text', { text: 'inner' })); expect(el.type).toBe('button'); expect(el.props.label).toBe('Go'); expect(el.children[0].type).toBe('text'); }); it('exports Fragment and styleWire helpers', () => { expect(Fragment).toBe('_fragment'); expect(styleWire({ padding: 'md' })).toEqual({ style: { padding: 'md' } }); }); it('ignores non-element objects without type', () => { const el = jsx('column', null, { foo: 1 }); expect(el.children).toEqual([]); }); });