mirror of
https://github.com/microsoft/playwright.git
synced 2024-10-06 01:17:33 +03:00
feat(ct): solid set props (#16813)
This commit is contained in:
parent
fb88b32926
commit
8d4a94bfd3
@ -17,10 +17,10 @@
|
||||
// @ts-check
|
||||
// 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('solid-js').JSX.Element} FrameworkComponent */
|
||||
/** @typedef {() => import('solid-js').JSX.Element} FrameworkComponent */
|
||||
|
||||
/** @type {Map<string, FrameworkComponent>} */
|
||||
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()]}`);
|
||||
|
||||
const componentFuncOrString = componentFunc || component.type;
|
||||
|
||||
if (component.kind !== 'jsx')
|
||||
throw new Error('Object mount notation is not supported');
|
||||
|
||||
return componentFuncOrString;
|
||||
return createComponent(componentFunc, component.props);
|
||||
}
|
||||
|
||||
window.playwrightMount = async (component, rootElement, hooksConfig) => {
|
||||
|
@ -1,3 +1,6 @@
|
||||
export default function Button() {
|
||||
return <button>Submit</button>
|
||||
type ButtonProps = {
|
||||
title: string;
|
||||
}
|
||||
export default function Button(props: ButtonProps) {
|
||||
return <button>{props.title}</button>
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ import Button from './components/Button';
|
||||
|
||||
test.use({ viewport: { width: 500, height: 500 } });
|
||||
|
||||
test('should work', async ({ mount }) => {
|
||||
const component = await mount(<Button />);
|
||||
test('props should work', async ({ mount }) => {
|
||||
const component = await mount(<Button title="Submit" />);
|
||||
await expect(component).toContainText('Submit');
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user