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

feat(testing): support to test web components #198

Merged
merged 11 commits into from
May 15, 2024
Merged

Conversation

aralroca
Copy link
Collaborator

Fixes #144

I have added support for testing web components, and I have also solved the problem of testing i18n translations by passing the "locale" option to the render. Also as an extra I have added the matcher toHaveElementByNodeName and the cleanup, necessary to clean the document.


Test Web Components after rendering

You can also test Web Components after rendering them. For example, you can test a custom element:

import { render, userEvent } from "brisa/test";
import { test, expect } from "bun:test";

test("web component", async () => {
  const { container } = await render(<custom-counter />);
  const counter = container.querySelector("custom-counter")!.shadowRoot!;
  const [increment, decrement] = counter.querySelectorAll("button");

  expect(counter).toContainTextContent("0");

  userEvent.click(increment);

  expect(counter).toContainTextContent("1");

  userEvent.click(decrement);

  expect(counter).toContainTextContent("0");
});

Tip

You can use the shadowRoot property to access the shadow DOM of a custom element.

@aralroca aralroca self-assigned this May 15, 2024
@aralroca aralroca merged commit bc9aeca into main May 15, 2024
0 of 2 checks passed
@aralroca aralroca deleted the testing-improvements branch May 15, 2024 22:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

testing tools to test brisa routes (pages and api)
1 participant