import { describe, it, expect } from 'vitest' import type { Assert, Equal } from './utils' import type { Handle, RemixNode } from '../lib/component' import { animateLayout, createMixin, on, ref } from '../index.ts' import type { Dispatched, MixinHandle, Props } from '../index.ts' type MixLeaf = mix extends ReadonlyArray ? MixLeaf : mix type FalsyMixValue = false | 0 | 0n | '' | null | undefined type NormalizeMixLeaf = Exclude, FalsyMixValue> type NormalizedMix = Array> | undefined describe('jsx', () => { it('creates an element', () => { let element =
Hello, world!
expect(element.type).toBe('div') expect(element.props.children).toEqual('Hello, world!') }) /* oxlint-disable eslint/no-unused-vars */ it('warns when the wrong type of a prop is used', () => { let element = Hello, world! // @ts-expect-error - wrong type let badElement = Hello, world! }) describe('intrinsic elements', () => { it('uses literal types for element props', () => { let good = // @ts-expect-error - wrong type let bad = }) it('infers the event target type from the element type', () => { let element = ( ) }) it('accepts nested mix values for host element JSX while render props still see arrays', () => { let passthrough = createMixin((_handle) => {}) let descriptor = passthrough() let withNested = expect(withNested.props.mix).toEqual([descriptor, descriptor]) }) }) describe('library managed attributes', () => { it('infers component setup and props', () => { function Counter(handle: Handle, setup: number) { let count = setup return (props: { label: string }) => { // no `props.setup` type componentProps = Assert> return ( ) } } let good = // @ts-expect-error - wrong type let bad = }) it('infers component setup and props with context', () => { function Counter(handle: Handle, setup: number) { let count = setup return (props: { label: string }) => { handle.context.set(count) // no `props.setup` type componentProps = Assert> return ( ) } } let good = }) it('accepts single or array mix values for component JSX while render props see arrays', () => { let passthrough = createMixin((handle) => {}) function Button() { return (props: Props<'button'>) => { type normalizedMix = Assert< Equal> > return