[READ-ONLY] Mirror of https://github.com/bombshell-dev/clack. Effortlessly build beautiful command-line apps bomb.sh/docs/clack/basics/getting-started/
cli command-line command-line-app node prompt prompts
5

Configure Feed

Select the types of activity you want to include in your feed.

wip: add some tests

James Garbutt (Jul 8, 2025, 2:52 PM +0100) eb79a94e 9312c087

+38 -11
+23 -6
packages/jsx/src/index.ts
··· 1 1 import type { ConfirmOptions } from '@clack/prompts'; 2 + import { confirm } from '@clack/prompts'; 2 3 3 4 namespace JSX { 4 5 export interface IntrinsicElements { 5 - confirm: ConfirmOptions; 6 6 } 7 7 8 - export type Element = unknown; 8 + export type Element = Promise<unknown>; 9 9 } 10 10 11 11 export type { JSX }; 12 12 13 - export function Confirm(_props: JSX.IntrinsicElements['confirm']): JSX.Element { 14 - return 'foo'; 13 + export function Confirm(props: ConfirmOptions): ReturnType<typeof confirm> { 14 + return confirm(props); 15 15 } 16 16 17 - export function jsx<T extends keyof JSX.IntrinsicElements>( 17 + export type Component = 18 + | typeof Confirm; 19 + 20 + function jsx<T extends keyof JSX.IntrinsicElements>( 18 21 tag: T, 19 22 props: JSX.IntrinsicElements[T], 20 23 _key?: string 24 + ): JSX.Element; 25 + function jsx<T extends Component>( 26 + fn: T, 27 + props: Parameters<T>[0], 28 + _key?: string 29 + ): JSX.Element; 30 + function jsx( 31 + tagOrFn: string | Component, 32 + props: unknown, 33 + _key?: string 21 34 ): JSX.Element { 22 - return 'foo'; 35 + if (typeof tagOrFn === 'function') { 36 + return (tagOrFn as (props: unknown) => JSX.Element)(props); 37 + } 38 + return Promise.resolve(null); 23 39 } 24 40 41 + export { jsx }; 25 42 export const jsxDEV = jsx;
+15 -5
packages/jsx/test/jsx.test.tsx
··· 12 12 }); 13 13 14 14 test('can render', async () => { 15 - const result = jsx('confirm', { 15 + const task = jsx(Confirm, { 16 16 message: 'foo?', 17 17 input, 18 18 output, 19 19 }); 20 - expect(result).to.equal('foo'); 20 + input.emit('keypress', '', { name: 'return' }); 21 + const result = await task; 22 + expect(result).to.equal(true); 21 23 }); 22 24 23 - test('can render JSX', () => { 24 - const result = <Confirm message="foo?" input={input} output={output} />; 25 - expect(result).to.equal('foo'); 25 + test('can render JSX', async () => { 26 + const task = (<Confirm message="foo?" input={input} output={output} />); 27 + input.emit('keypress', '', { name: 'return' }); 28 + const result = await task; 29 + expect(result).to.equal(true); 30 + }); 31 + 32 + test('unknown elements are null', async () => { 33 + const task = jsx('unknown-nonsense' as never, {} as never); 34 + const result = await task; 35 + expect(result).to.equal(null); 26 36 }); 27 37 });