This commit is contained in:
sand4rt 2022-08-23 20:37:55 +02:00 коммит произвёл GitHub
Родитель 31a47d4273
Коммит e194b2ae6b
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 73 добавлений и 13 удалений

24
packages/playwright-ct-vue2/index.d.ts поставляемый
Просмотреть файл

@ -34,24 +34,22 @@ export type PlaywrightTestConfig = Omit<BasePlaywrightTestConfig, 'use'> & {
}
};
interface MountResult extends Locator {
export interface MountOptions<Props = Record<string, unknown>> {
props?: Props,
slots?: Record<string, unknown>,
on?: Record<string, Function>,
hooksConfig?: any,
}
interface MountResult<Props = Record<string, unknown>> extends Locator {
unmount(): Promise<void>;
rerender(options: { props: Props }): Promise<void>
}
export interface ComponentFixtures {
mount(component: JSX.Element): Promise<MountResult>;
mount(component: any, options?: {
props?: { [key: string]: any },
slots?: { [key: string]: any },
on?: { [key: string]: Function },
hooksConfig?: any,
}): Promise<MountResult>;
mount<Props>(component: any, options: {
props: Props,
slots?: { [key: string]: any },
on?: { [key: string]: Function },
hooksConfig?: any,
}): Promise<MountResult>;
mount(component: any, options?: MountOptions): Promise<MountResult>;
mount<Props>(component: any, options: MountOptions<Required<Props>>): Promise<MountResult<Props>>;
}
export const test: TestType<

Просмотреть файл

@ -157,3 +157,12 @@ window.playwrightUnmount = async rootElement => {
component.$destroy();
component.$el.remove();
};
window.playwrightRerender = async (element, options) => {
const component = /** @type {any} */(element)[instanceKey];
if (!component)
throw new Error('Component was not mounted');
for (const [key, value] of Object.entries(/** @type {any} */(options).props))
component.$children[0][key] = value;
};

Просмотреть файл

@ -0,0 +1,21 @@
<template>
<div>
<span id="remount-count">{{ remountCount }}</span>
<span id="rerender-count">{{ count }}</span>
</div>
</template>
<script>
let remountCount = 0;
export default {
name: 'Button',
props: ['count'],
data() {
return { remountCount }
},
beforeCreate() {
remountCount++;
},
}
</script>

Просмотреть файл

@ -1,5 +1,6 @@
import { test, expect } from '@playwright/experimental-ct-vue2'
import Button from './components/Button.vue'
import Counter from './components/Counter.vue'
import DefaultSlot from './components/DefaultSlot.vue'
import NamedSlots from './components/NamedSlots.vue'
@ -10,6 +11,19 @@ test('props should work', async ({ mount }) => {
await expect(component).toContainText('Submit')
})
test('renderer and keep the component instance intact', async ({ mount }) => {
const component = await mount(<Counter count={9001} />)
await expect(component.locator('#rerender-count')).toContainText('9001')
await component.rerender({ props: { count: 1337 } })
await expect(component.locator('#rerender-count')).toContainText('1337')
await component.rerender({ props: { count: 42 } })
await expect(component.locator('#rerender-count')).toContainText('42')
await expect(component.locator('#remount-count')).toContainText('1')
})
test('event should work', async ({ mount }) => {
const messages = []
const component = await mount(<Button title='Submit' v-on:submit={data => {

Просмотреть файл

@ -1,6 +1,7 @@
import { test, expect } from '@playwright/experimental-ct-vue2'
import Button from './components/Button.vue'
import Counter from './components/Counter.vue'
import DefaultSlot from './components/DefaultSlot.vue'
import NamedSlots from './components/NamedSlots.vue'
@ -15,6 +16,23 @@ test('props should work', async ({ mount }) => {
await expect(component).toContainText('Submit')
})
test('renderer and keep the component instance intact', async ({ mount }) => {
const component = await mount<{ count: number }>(Counter, {
props: {
count: 9001
}
})
await expect(component.locator('#rerender-count')).toContainText('9001')
await component.rerender({ props: { count: 1337 } })
await expect(component.locator('#rerender-count')).toContainText('1337')
await component.rerender({ props: { count: 42 } })
await expect(component.locator('#rerender-count')).toContainText('42')
await expect(component.locator('#remount-count')).toContainText('1')
})
test('event should work', async ({ mount }) => {
const messages = []
const component = await mount(Button, {