feat(ct): vue2 type safe mount props (#23194)
This commit is contained in:
parent
dc5e201611
commit
98cba15938
46
packages/playwright-ct-vue2/index.d.ts
vendored
46
packages/playwright-ct-vue2/index.d.ts
vendored
|
|
@ -36,20 +36,30 @@ export type PlaywrightTestConfig<T = {}, W = {}> = Omit<BasePlaywrightTestConfig
|
||||||
};
|
};
|
||||||
|
|
||||||
type Slot = string | string[];
|
type Slot = string | string[];
|
||||||
|
type ComponentSlots = Record<string, Slot> & { default?: Slot };
|
||||||
|
|
||||||
export interface MountOptions<
|
type ComponentEvents = Record<string, Function>;
|
||||||
HooksConfig extends JsonObject,
|
|
||||||
Props extends Record<string, unknown>
|
// Copied from: https://github.com/vuejs/language-tools/blob/master/packages/vue-component-type-helpers/index.d.ts#L10-L13
|
||||||
> {
|
type ComponentProps<T> =
|
||||||
props?: Props;
|
T extends new () => { $props: infer P; } ? NonNullable<P> :
|
||||||
slots?: Record<string, Slot> & { default?: Slot };
|
T extends (props: infer P, ...args: any) => any ? P :
|
||||||
on?: Record<string, Function>;
|
{};
|
||||||
|
|
||||||
|
export interface MountOptions<HooksConfig extends JsonObject, Component> {
|
||||||
|
props?: ComponentProps<Component>;
|
||||||
|
slots?: ComponentSlots;
|
||||||
|
on?: ComponentEvents;
|
||||||
hooksConfig?: HooksConfig;
|
hooksConfig?: HooksConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface MountResult<Props extends Record<string, unknown>> extends Locator {
|
interface MountResult<Component> extends Locator {
|
||||||
unmount(): Promise<void>;
|
unmount(): Promise<void>;
|
||||||
update(options: Omit<MountOptions<never, Props>, 'hooksConfig'>): Promise<void>;
|
update(options: {
|
||||||
|
props?: Partial<ComponentProps<Component>>;
|
||||||
|
slots?: Partial<ComponentSlots>;
|
||||||
|
on?: Partial<ComponentEvents>;
|
||||||
|
}): Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface MountResultJsx extends Locator {
|
interface MountResultJsx extends Locator {
|
||||||
|
|
@ -59,17 +69,10 @@ interface MountResultJsx extends Locator {
|
||||||
|
|
||||||
export interface ComponentFixtures {
|
export interface ComponentFixtures {
|
||||||
mount(component: JSX.Element): Promise<MountResultJsx>;
|
mount(component: JSX.Element): Promise<MountResultJsx>;
|
||||||
mount<HooksConfig extends JsonObject>(
|
mount<HooksConfig extends JsonObject, Component = unknown>(
|
||||||
component: any,
|
component: Component,
|
||||||
options?: MountOptions<HooksConfig, Record<string, unknown>>
|
options?: MountOptions<HooksConfig, Component>
|
||||||
): Promise<MountResult<Record<string, unknown>>>;
|
): Promise<MountResult<Component>>;
|
||||||
mount<
|
|
||||||
HooksConfig extends JsonObject,
|
|
||||||
Props extends Record<string, unknown> = Record<string, unknown>
|
|
||||||
>(
|
|
||||||
component: any,
|
|
||||||
options: MountOptions<HooksConfig, never> & { props: Props }
|
|
||||||
): Promise<MountResult<Props>>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const test: TestType<
|
export const test: TestType<
|
||||||
|
|
@ -77,9 +80,6 @@ export const test: TestType<
|
||||||
PlaywrightWorkerArgs & PlaywrightWorkerOptions
|
PlaywrightWorkerArgs & PlaywrightWorkerOptions
|
||||||
>;
|
>;
|
||||||
|
|
||||||
/**
|
|
||||||
* Defines Playwright config
|
|
||||||
*/
|
|
||||||
export function defineConfig(config: PlaywrightTestConfig): PlaywrightTestConfig;
|
export function defineConfig(config: PlaywrightTestConfig): PlaywrightTestConfig;
|
||||||
export function defineConfig<T>(config: PlaywrightTestConfig<T>): PlaywrightTestConfig<T>;
|
export function defineConfig<T>(config: PlaywrightTestConfig<T>): PlaywrightTestConfig<T>;
|
||||||
export function defineConfig<T, W>(config: PlaywrightTestConfig<T, W>): PlaywrightTestConfig<T, W>;
|
export function defineConfig<T, W>(config: PlaywrightTestConfig<T, W>): PlaywrightTestConfig<T, W>;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue