mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
feat(ct): solid update (#18074)
closes: https://github.com/microsoft/playwright/issues/15057 closes: https://github.com/microsoft/playwright/issues/15919 Signed-off-by: sand4rt <info@mesander.com>
This commit is contained in:
parent
84daeafb3a
commit
d8b037c559
1
packages/playwright-ct-solid/index.d.ts
vendored
1
packages/playwright-ct-solid/index.d.ts
vendored
@ -45,6 +45,7 @@ export interface MountOptions<HooksConfig extends JsonObject> {
|
||||
|
||||
interface MountResult extends Locator {
|
||||
unmount(): Promise<void>;
|
||||
update(component: JSX.Element): Promise<void>;
|
||||
}
|
||||
|
||||
export interface ComponentFixtures {
|
||||
|
||||
@ -95,3 +95,8 @@ window.playwrightUnmount = async rootElement => {
|
||||
|
||||
unmount();
|
||||
};
|
||||
|
||||
window.playwrightUpdate = async (rootElement, component) => {
|
||||
window.playwrightUnmount(rootElement);
|
||||
window.playwrightMount(component, rootElement, {});
|
||||
};
|
||||
|
||||
19
tests/components/ct-solid/src/components/Counter.tsx
Normal file
19
tests/components/ct-solid/src/components/Counter.tsx
Normal file
@ -0,0 +1,19 @@
|
||||
import { createSignal } from "solid-js";
|
||||
|
||||
type CounterProps = {
|
||||
count?: number;
|
||||
onClick?(props: string): void;
|
||||
children?: any;
|
||||
}
|
||||
|
||||
let _remountCount = 1;
|
||||
|
||||
export default function Counter(props: CounterProps) {
|
||||
const [remountCount, setRemountCount] = createSignal(_remountCount++);
|
||||
return <div onClick={() => props.onClick?.('hello')}>
|
||||
<div data-testid="props">{ props.count }</div>
|
||||
<div data-testid="remount-count">{ remountCount }</div>
|
||||
{ props.children }
|
||||
</div>
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import { test, expect } from '@playwright/experimental-ct-solid';
|
||||
import Button from './components/Button';
|
||||
import Counter from './components/Counter';
|
||||
import DefaultChildren from './components/DefaultChildren';
|
||||
import MultipleChildren from './components/MultipleChildren';
|
||||
import MultiRoot from './components/MultiRoot';
|
||||
@ -16,7 +17,54 @@ test('render props', async ({ mount }) => {
|
||||
test('render attributes', async ({ mount }) => {
|
||||
const component = await mount(<Button className="primary" title="Submit" />)
|
||||
await expect(component).toHaveClass('primary');
|
||||
})
|
||||
});
|
||||
|
||||
test('renderer updates props without remounting', async ({ mount }) => {
|
||||
const component = await mount(<Counter count={9001} />)
|
||||
await expect(component.getByTestId('props')).toContainText('9001')
|
||||
|
||||
await component.update(<Counter count={1337} />)
|
||||
await expect(component).not.toContainText('9001')
|
||||
await expect(component.getByTestId('props')).toContainText('1337')
|
||||
|
||||
/**
|
||||
* Ideally toContainText('2') should be toContainText('1')
|
||||
* However it seems impossible to update the props, slots or events of a rendered component
|
||||
*/
|
||||
await expect(component.getByTestId('remount-count')).toContainText('2')
|
||||
});
|
||||
|
||||
test('renderer updates slots without remounting', async ({ mount }) => {
|
||||
const component = await mount(<Counter>Default Slot</Counter>)
|
||||
await expect(component).toContainText('Default Slot')
|
||||
|
||||
await component.update(<Counter>Test Slot</Counter>)
|
||||
await expect(component).not.toContainText('Default Slot')
|
||||
await expect(component).toContainText('Test Slot')
|
||||
|
||||
/**
|
||||
* Ideally toContainText('2') should be toContainText('1')
|
||||
* However it seems impossible to update the props, slots or events of a rendered component
|
||||
*/
|
||||
await expect(component.getByTestId('remount-count')).toContainText('2')
|
||||
});
|
||||
|
||||
test('renderer updates callbacks without remounting', async ({ mount }) => {
|
||||
const component = await mount(<Counter />)
|
||||
|
||||
const messages: string[] = []
|
||||
await component.update(<Counter onClick={message => {
|
||||
messages.push(message)
|
||||
}} />)
|
||||
await component.click();
|
||||
expect(messages).toEqual(['hello'])
|
||||
|
||||
/**
|
||||
* Ideally toContainText('2') should be toContainText('1')
|
||||
* However it seems impossible to update the props, slots or events of a rendered component
|
||||
*/
|
||||
await expect(component.getByTestId('remount-count')).toContainText('2')
|
||||
});
|
||||
|
||||
test('execute callback when the button is clicked', async ({ mount }) => {
|
||||
const messages: string[] = [];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user