import { describe, test, expect } from 'bun:test'
import { define } from '../index'
import { renderToString, getStylesCSS, parseCSS } from './test_helpers'
describe('define - basic functionality', () => {
test('creates a component function', () => {
const Component = define({
display: 'flex'
})
expect(typeof Component).toBe('function')
})
test('component returns a JSX element', () => {
const Component = define({
display: 'flex'
})
const result = Component({})
expect(result).toBeDefined()
expect(typeof result).toBe('object')
})
test('applies className to rendered element', () => {
const Component = define('MyComponent', {
display: 'flex'
})
const html = renderToString(Component({}))
expect(html).toContain('class="MyComponent"')
})
test('generates unique anonymous component names', () => {
const Component1 = define({ display: 'flex' })
const Component2 = define({ display: 'block' })
const html1 = renderToString(Component1({}))
const html2 = renderToString(Component2({}))
// Should have different auto-generated names
expect(html1).toMatch(/class="Div\d*"/)
expect(html2).toMatch(/class="Div\d*"/)
expect(html1).not.toBe(html2)
})
test('renders default div element', () => {
const Component = define('DivTest', {
display: 'flex'
})
const html = renderToString(Component({}))
expect(html).toContain('
')
})
test('respects custom base element', () => {
const Component = define('ButtonTest', {
base: 'button',
color: 'blue'
})
const html = renderToString(Component({}))
expect(html).toContain('