feat(ct): solid set props (#16813)

This commit is contained in:
sand4rt 2022-08-25 17:40:14 +02:00 committed by GitHub
parent fb88b32926
commit 8d4a94bfd3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 10 deletions

View file

@ -17,10 +17,10 @@
// @ts-check // @ts-check
// This file is injected into the registry as text, no dependencies are allowed. // This file is injected into the registry as text, no dependencies are allowed.
import { render as solidRender } from 'solid-js/web'; import { render as solidRender, createComponent } from 'solid-js/web';
/** @typedef {import('../playwright-test/types/component').Component} Component */ /** @typedef {import('../playwright-test/types/component').Component} Component */
/** @typedef {import('solid-js').JSX.Element} FrameworkComponent */ /** @typedef {() => import('solid-js').JSX.Element} FrameworkComponent */
/** @type {Map<string, FrameworkComponent>} */ /** @type {Map<string, FrameworkComponent>} */
const registry = new Map(); const registry = new Map();
@ -48,15 +48,13 @@ function render(component) {
} }
} }
if (!componentFunc && component.type[0].toUpperCase() === component.type[0]) if (!componentFunc)
throw new Error(`Unregistered component: ${component.type}. Following components are registered: ${[...registry.keys()]}`); throw new Error(`Unregistered component: ${component.type}. Following components are registered: ${[...registry.keys()]}`);
const componentFuncOrString = componentFunc || component.type;
if (component.kind !== 'jsx') if (component.kind !== 'jsx')
throw new Error('Object mount notation is not supported'); throw new Error('Object mount notation is not supported');
return componentFuncOrString; return createComponent(componentFunc, component.props);
} }
window.playwrightMount = async (component, rootElement, hooksConfig) => { window.playwrightMount = async (component, rootElement, hooksConfig) => {

View file

@ -1,3 +1,6 @@
export default function Button() { type ButtonProps = {
return <button>Submit</button> title: string;
}
export default function Button(props: ButtonProps) {
return <button>{props.title}</button>
} }

View file

@ -3,7 +3,7 @@ import Button from './components/Button';
test.use({ viewport: { width: 500, height: 500 } }); test.use({ viewport: { width: 500, height: 500 } });
test('should work', async ({ mount }) => { test('props should work', async ({ mount }) => {
const component = await mount(<Button />); const component = await mount(<Button title="Submit" />);
await expect(component).toContainText('Submit'); await expect(component).toContainText('Submit');
}); });