diff --git a/packages/playwright-ct-vue2/index.d.ts b/packages/playwright-ct-vue2/index.d.ts index 7962cad690f1c..cd007fffe2fe2 100644 --- a/packages/playwright-ct-vue2/index.d.ts +++ b/packages/playwright-ct-vue2/index.d.ts @@ -34,8 +34,9 @@ export type PlaywrightTestConfig = Omit & { } }; -interface MountResult extends Locator { +interface MountResult extends Locator { unmount(): Promise; + setProps(props: Partial): Promise; } export interface ComponentFixtures { @@ -51,7 +52,7 @@ export interface ComponentFixtures { slots?: { [key: string]: any }, on?: { [key: string]: Function }, hooksConfig?: any, - }): Promise; + }): Promise>; } export const test: TestType< diff --git a/packages/playwright-ct-vue2/registerSource.mjs b/packages/playwright-ct-vue2/registerSource.mjs index 3edb704ab5a01..87839a69306b7 100644 --- a/packages/playwright-ct-vue2/registerSource.mjs +++ b/packages/playwright-ct-vue2/registerSource.mjs @@ -134,6 +134,8 @@ function render(component, h) { return wrapper; } +const instanceKey = Symbol('instanceKey'); + window.playwrightMount = async (component, rootElement, hooksConfig) => { for (const hook of /** @type {any} */(window).__pw_hooks_before_mount || []) await hook({ hooksConfig }); @@ -156,4 +158,11 @@ window.playwrightUnmount = async element => { element.remove(); }; -const instanceKey = Symbol('instanceKey'); +window.playwrightSetProps = async (element, props) => { + const component = /** @type {any} */(element)[instanceKey]; + if (!component) + throw new Error('Component was not mounted'); + + for (const [key, value] of Object.entries(props)) + component.$children[0][key] = value; +}; diff --git a/tests/components/ct-vue-cli/src/notation-jsx.spec.tsx b/tests/components/ct-vue-cli/src/notation-jsx.spec.tsx index 3ecea3cac2433..8618c7f8176e8 100644 --- a/tests/components/ct-vue-cli/src/notation-jsx.spec.tsx +++ b/tests/components/ct-vue-cli/src/notation-jsx.spec.tsx @@ -10,6 +10,13 @@ test('props should work', async ({ mount }) => { await expect(component).toContainText('Submit') }) +test('update props should work', async ({ mount }) => { + const component = await mount() + await expect(component).toContainText('Submit') + await component.setProps({ title: 'Loading' }) + await expect(component).toContainText('Loading') +}) + test('event should work', async ({ mount }) => { const messages = [] const component = await mount() + await expect(component).toContainText('Submit') + await component.setProps({ title: 'Loading' }) + await expect(component).toContainText('Loading') +}) + test('event should work', async ({ mount }) => { const messages = [] const component = await mount(