Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(ct): multi framework typical example #30658

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
97 changes: 95 additions & 2 deletions docs/src/test-components-js.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,24 @@ Playwright Test can now test your components.

Here is what a typical component test looks like:

<Tabs
defaultValue="react"
values={[
{label: 'React', value: 'react'},
{label: 'Solid', value: 'solid'},
{label: 'Svelte', value: 'svelte'},
{label: 'Vue', value: 'vue'},
]
}>
<TabItem value="react">

```js
test('event should work', async ({ mount }) => {
test('trigger event upon button click', async ({ mount }) => {
let clicked = false;

// Mount a component. Returns locator pointing to the component.
const component = await mount(
<Button title="Submit" onClick={() => { clicked = true }}></Button>
<Button title="Submit" onClick={() => { clicked = true }} />
);

// As with any Playwright test, assert locator text.
Expand All @@ -38,6 +49,88 @@ test('event should work', async ({ mount }) => {
});
```

</TabItem>

<TabItem value="solid">

```js
test('trigger event upon button click', async ({ mount }) => {
let clicked = false;

// Mount a component. Returns locator pointing to the component.
const component = await mount(
<Button title="Submit" onClick={() => { clicked = true }} />
);

// As with any Playwright test, assert locator text.
await expect(component).toContainText('Submit');

// Perform locator click. This will trigger the event.
await component.click();

// Assert that respective events have been fired.
expect(clicked).toBeTruthy();
});
```

</TabItem>

<TabItem value="svelte">

```js
test('trigger event upon button click', async ({ mount }) => {
let clicked = false;

// Mount a component. Returns locator pointing to the component.
const component = await mount(Button, {
props: { title: 'Submit' },
on: {
onClick() { clicked = true }
}
});

// As with any Playwright test, assert locator text.
await expect(component).toContainText('Submit');

// Perform locator click. This will trigger the event.
await component.click();

// Assert that respective events have been fired.
expect(clicked).toBeTruthy();
});
```

</TabItem>

<TabItem value="vue">

```js
test('trigger event upon button click', async ({ mount }) => {
let clicked = false;

// Mount a component. Returns locator pointing to the component.
const component = await mount(Button, {
props: { title: 'Submit' },
on: {
onClick() { clicked = true }
}
});

// As with any Playwright test, assert locator text.
await expect(component).toContainText('Submit');

// Perform locator click. This will trigger the event.
await component.click();

// Assert that respective events have been fired.
expect(clicked).toBeTruthy();
});
```

</TabItem>

</Tabs>

## How to get started

Adding Playwright Test to an existing project is easy. Below are the steps to enable Playwright Test for a React, Vue, Svelte or Solid project.
Expand Down