Skip to content

Commit

Permalink
feat: infer prop types
Browse files Browse the repository at this point in the history
  • Loading branch information
sand4rt committed Jan 1, 2023
1 parent c558185 commit 5ec814d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion ct-web/src/components/Counter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
let remountCount = 0

export class Counter extends HTMLElement {
set count(count: string) {
set count(count: number) {
this.innerHTML = `
<div>
<div id="props">${count}</div>
Expand Down
20 changes: 11 additions & 9 deletions playwright-ct-web/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,28 @@ type JsonValue = JsonPrimitive | JsonObject | JsonArray;
type JsonArray = JsonValue[];
type JsonObject = { [Key in string]?: JsonValue };

// TODO: get props, probably by filter readonly and function types?
type ComponentProps<Component extends HTMLElement> = Partial<Component>;

type Slot = string | string[];

export interface MountOptions {
props?: Props;
export interface MountOptions<HooksConfig extends JsonObject, Component extends HTMLElement> {
props?: ComponentProps<Component>;
slots?: Record<string, Slot> & { default?: Slot };
on?: Record<string, Function>;
hooksConfig?: HooksConfig;
}

interface MountResult<
Props extends Record<string, unknown>
> extends Locator {
interface MountResult<Component extends HTMLElement> extends Locator {
unmount(): Promise<void>;
update(options: Omit<MountOptions<never, Props>, 'hooksConfig'>): Promise<void>;
update(options: Omit<MountOptions<never, Component>, 'hooksConfig'>): Promise<void>;
}

export interface ComponentFixtures {
mount<HooksConfig extends JsonObject>(
component: new (...args: any[]) => HTMLElement, options?: MountOptions
): Promise<MountResult<any>>;
mount<HooksConfig extends JsonObject, Component extends HTMLElement = HTMLElement>(
component: new (...args: any[]) => Component,
options?: MountOptions<HooksConfig, Component>
): Promise<MountResult<Component>>;
}

export const test: TestType<
Expand Down
2 changes: 1 addition & 1 deletion playwright-ct-web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sand4rt/experimental-ct-web",
"version": "0.0.8",
"version": "0.0.9",
"description": "Playwright Component Testing for Web Components",
"homepage": "https://playwright.dev",
"engines": {
Expand Down

0 comments on commit 5ec814d

Please sign in to comment.