feat(ct): solid default child (#16839)

This commit is contained in:
sand4rt 2022-08-27 00:48:05 +02:00 committed by GitHub
parent c3f39faefc
commit 996468d4b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 2 deletions

View file

@ -54,7 +54,10 @@ function render(component) {
if (component.kind !== 'jsx')
throw new Error('Object mount notation is not supported');
return createComponent(componentFunc, component.props);
return createComponent(componentFunc, {
children: component.children,
...component.props
});
}
const unmountKey = Symbol('disposeKey');

View file

@ -0,0 +1,15 @@
type DefaultChildrenProps = {
children?: any;
}
export default function DefaultChildren(props: DefaultChildrenProps) {
return <div>
<h1>Welcome!</h1>
<main>
{props.children}
</main>
<footer>
Thanks for visiting.
</footer>
</div>
}

View file

@ -1,5 +1,6 @@
import { test, expect } from '@playwright/experimental-ct-solid'
import Button from './components/Button';
import DefaultChildren from './components/DefaultChildren';
import MultiRoot from './components/MultiRoot';
test.use({ viewport: { width: 500, height: 500 } });
@ -16,7 +17,14 @@ test('callback should work', async ({ mount }) => {
}}></Button>)
await component.click()
expect(messages).toEqual(['hello'])
});
})
test('default child should work', async ({ mount }) => {
const component = await mount(<DefaultChildren>
Main Content
</DefaultChildren>)
await expect(component).toContainText('Main Content')
})
test('should unmount', async ({ page, mount }) => {
const component = await mount(<Button title="Submit" />)