A collection of useful code snippets and examples for writing End to End tests in a Stencil project.
import { newE2EPage } from "@stencil/core/testing";
describe("example", () => {
it("should render a my-comp", async () => {
const page = await newE2EPage();
await page.setContent(`<my-comp></my-comp>`);
const el = await page.find("my-comp");
expect(el).not.toBeNull();
});
});
const input = await page.find("my-comp >>> input");
await input.press("8");
await input.press("KeyM");
await input.press(" ");
await page.keyboard.down("Shift");
await input.press("KeyM");
await page.keyboard.up("Shift");
const el = await page.find("my-comp >>> .close-button");
const elm = await page.find("my-comp");
const value = await elm.callMethod("methodName");
await page.setContent(`<my-comp></my-comp>`);
await page.$eval("my-comp", elm => {
elm.first = "Marty";
});
await page.waitForChanges();
await page.mouse.move(200, 300);
await page.mouse.down();
await page.mouse.move(240, 380);
await page.mouse.up();
const wrapper = await page.find("my-comp >>> .visible");
const visible = await wrapper.isVisible();
expect(visible).toBe(true);
const component = await page.find("my-comp");
expect(component).toHaveAttribute("attribute");
expect(component).toEqualAttribute("attribute", "value");
const changedEvent = await page.spyOnEvent("myEventName");
// perform actions that should fire the event
await page.waitForChanges();
expect(changedEvent).toHaveReceivedEventTimes(1);
const changedEvent = await page.spyOnEvent("myEventName");
// perform actions that should fire the event
await page.waitForChanges();
expect(changedEvent).toHaveFirstReceivedEventDetail(true);
const component = await page.find("my-comp");
let value = await slider.getProperty("value");
expect(value).toBe(30);
// perform actions that should change the value
expect(await component.getProperty("value")).toBe(31);
const children = await page.findAll("my-comp >>> .child");
expect(children.length).toBe(11);
const button = await page.find("my-comp >>> button");
const text = button.textContent;
expect(text).toBe("hello world");