Skip to content

[Feature] improve type safety hooksConfig #19933

@sand4rt

Description

@sand4rt

The idea comes from @tannerlinsley: https://youtu.be/DXbfDKoMzWY?t=1467.

// ./playwright/index.tsx
import { beforeMount } from '@playwright/experimental-ct-solid/hooks';

// Override HooksConfig so there is no need to specify it as a `mount<HooksConfig>` generic
declare module '@playwright/experimental-ct-solid/hooks' { 
  interface RegisterHooksConfig {
    route: string;
  }
}

beforeMount(async ({ hooksConfig }) => {
  hooksConfig.DOES_NOT_EXSISTS; // throws an error without specifying the generic
});
// App.test.tsx
import { expect, test } from "@playwright/experimental-ct-solid";
import { App } from "./app";

test('type check', async ({ mount }) => {
  const component = await mount(<App />, { 
    hooksConfig: { route: '' } // is typesafe without specifying the `mount<HooksConfig>` generic
  });

  await expect(component.getByText('label')).toBeVisible();
});

related: #18616

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions