Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ct): vue2 set props #16078

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/playwright-ct-vue2/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ export type PlaywrightTestConfig = Omit<BasePlaywrightTestConfig, 'use'> & {
}
};

interface MountResult extends Locator {
interface MountResult<Props = { [key: string]: any }> extends Locator {
unmount(): Promise<void>;
setProps(props: Partial<Props>): Promise<void>;
}

export interface ComponentFixtures {
Expand All @@ -51,7 +52,7 @@ export interface ComponentFixtures {
slots?: { [key: string]: any },
on?: { [key: string]: Function },
hooksConfig?: any,
}): Promise<MountResult>;
}): Promise<MountResult<Props>>;
}

export const test: TestType<
Expand Down
11 changes: 10 additions & 1 deletion packages/playwright-ct-vue2/registerSource.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand All @@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not look like something documented to update the UI upon the changes. Is this something VTU uses?

};
7 changes: 7 additions & 0 deletions tests/components/ct-vue-cli/src/notation-jsx.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(<Button title='Submit'></Button>)
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(<Button title='Submit' v-on:submit={data => {
Expand Down
11 changes: 11 additions & 0 deletions tests/components/ct-vue-cli/src/notation-vue.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ test('props should work', async ({ mount }) => {
await expect(component).toContainText('Submit')
})

test('update props should work', async ({ mount }) => {
const component = await mount(Button, {
props: {
title: 'Submit'
}
});
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(Button, {
Expand Down
7 changes: 7 additions & 0 deletions tests/components/ct-vue2-cli/src/notation-jsx.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(<Button title='Submit'></Button>)
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(<Button title='Submit' v-on:submit={data => {
Expand Down
11 changes: 11 additions & 0 deletions tests/components/ct-vue2-cli/src/notation-vue.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ test('props should work', async ({ mount }) => {
await expect(component).toContainText('Submit')
})

test('update props should work', async ({ mount }) => {
const component = await mount(Button, {
props: {
title: 'Submit'
}
});
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(Button, {
Expand Down