Skip to content

Commit 590c330

Browse files
authored
Merge pull request #27 from 100monkeys-ai/fix-render-component-mount-14696471798748370391
🧹 [code health] Implement renderComponent component mounting
2 parents d1262d5 + 507fe9c commit 590c330

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

fsl/test/src/mocks.fx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff 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 {

fsl/test/tests/test.test.fx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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

55
describe('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+
})

0 commit comments

Comments
 (0)