Skip to content

Latest commit

 

History

History
60 lines (46 loc) · 1.78 KB

README.md

File metadata and controls

60 lines (46 loc) · 1.78 KB

Playwright Web component testing

Note The API has been designed to closely resemble Playwright's API wherever applicable. This library is (without guarantee) aimed at facilitating a smooth transition to Playwright once it offers official support for Web components. It is important to take into account that this library will reach end of life when Playwright has official support for Web component testing.

To push for official support, feedback in the form of github issues and or stars is appreciated!

Usage

First, install playwright and initialize component testing, then install the web component adapter.

npm init playwright@latest -- --ct
npm install -D @sand4rt/experimental-ct-web

After installing the config needs to be modified:

import { defineConfig } from '@sand4rt/experimental-ct-web';

export default defineConfig({
  // ...Your config
});

Now you can start adding your first test:

// Button.ts
import { LitElement, html } from 'lit';
import { customElement, property } from 'lit/decorators.js';

@customElement('button-component')
export class Button extends LitElement {
  @property({ type: String })
  title!: string;

  render() {
    return html`<button>${this.title}</button>`;
  }
}
// Button.test.ts
import { test, expect } from '@sand4rt/experimental-ct-web';
import { Button } from './components/Button';

test('render props', async ({ mount }) => {
  const component = await mount(Button, {
    props: {
      title: 'Submit',
    },
  });
  await expect(component).toContainText('Submit');
});

See the official playwright component testing documentation and the tests for lit and native web components for more information on how to use it.