File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -21,8 +21,12 @@ export async function renderComponent(
2121 component: unknown,
2222 props?: Record<string, unknown>
2323): Promise<RenderResult> {
24- // TODO: Mount the component using the Forge runtime in test mode
2524 const container = document.createElement('div')
25+
26+ const componentFn = component as (props: Record<string, unknown>) => Element
27+ const element = componentFn(props ?? {})
28+ container.appendChild(element)
29+
2630 document.body.appendChild(container)
2731
2832 return {
Original file line number Diff line number Diff line change 11// forge:test self-tests
22// These tests verify the test runner's own assertion API.
3- import { describe, it, expect } from '../src/index.fx'
3+ import { describe, it, expect, renderComponent } from '../src/index.fx'
44
55describe('expect().toBe', () => {
66 it('passes for identical primitives', () => {
@@ -28,3 +28,20 @@ describe('expect().toThrow', () => {
2828 expect(() => { throw new Error('boom') }).toThrow('boom')
2929 })
3030})
31+
32+ describe('renderComponent', () => {
33+ it('mounts a component and renders its output', async () => {
34+ // Dummy component function mimicking compiled Forge output
35+ const MyComponent = (props: { title?: string } = {}) => {
36+ const el = document.createElement('div')
37+ el.textContent = props.title ?? 'Hello World'
38+ return el
39+ }
40+
41+ const { getByText, unmount } = await renderComponent(MyComponent, { title: 'Test Component' })
42+
43+ expect(getByText('Test Component')).toBeDefined()
44+
45+ unmount()
46+ })
47+ })
You can’t perform that action at this time.
0 commit comments