Skip to content
Closed
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
34 changes: 34 additions & 0 deletions docs/src/test-components-js.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ component is mounted using this script. It can be either a `.js`, `.ts`, `.jsx`
values={[
{label: 'React', value: 'react'},
{label: 'Vue', value: 'vue'},
{label: 'Svelte', value: 'svelte'},
]
}>
<TabItem value="react">
Expand Down Expand Up @@ -488,6 +489,39 @@ You can use `beforeMount` and `afterMount` hooks to configure your app. This let

</TabItem>

<TabItem value="svelte">

```ts title="playwright/index.ts"
import { beforeMount, afterMount } from '@playwright/experimental-ct-svelte/hooks';

export type HooksConfig = {
context?: string;
}

beforeMount<HooksConfig>(async ({ App, hooksConfig }) => {
return new App({
context: new Map([['context-key', hooksConfig?.context]]),
});
});
```

```ts title="src/components/context.spec.ts"
import { test, expect } from '@playwright/experimental-ct-svelte';
import type { HooksConfig } from '../playwright';
import Context from './context.svelte';

test('configure context through hooks config', async ({ mount }) => {
const component = await mount<HooksConfig>(Context, {
hooksConfig: {
context: 'context-value',
},
});
await expect(component).toContainText('context-value');
});
```

</TabItem>

</Tabs>

### unmount
Expand Down