Variable testWebConst

testWeb: {
    cleanupRender: () => void;
    click: (element: Element) => Promise<void>;
    deleteInputText: (
        inputElement: Readonly<HTMLInputElement>,
    ) => Promise<void>;
    ensureFocus: (element: Element, maxAttemptCount?: number) => Promise<void>;
    moveMouseTo: (element: Element) => Promise<void>;
    render: <T extends Element>(
        template: LitHTMLRenderable,
        options?: FixtureOptions,
    ) => Promise<T>;
    typeIntoInput: (
        text: string,
        inputElement: Readonly<HTMLInputElement>,
    ) => Promise<void>;
    typeText: (text: string) => Promise<void>;
} = ...

A suite of web test helpers. This is only accessible within a browser runtime. If accessed outside of a browser runtime, it'll be an Error instead of a collection of test helpers.

Type declaration

  • cleanupRender: () => void

    Cleans up all rendered test HTML by removing the actual wrapper nodes. Common use case is at the end of each test.

  • click: (element: Element) => Promise<void>

    Clicks the center of the given element.

  • deleteInputText: (inputElement: Readonly<HTMLInputElement>) => Promise<void>

    Deletes all text that has been typed into the given <input> element.

  • ensureFocus: (element: Element, maxAttemptCount?: number) => Promise<void>

    Repeatedly tries to focus the given element until it is focused.

  • moveMouseTo: (element: Element) => Promise<void>

    Moves the mouse to the center of the given element.

  • render: <T extends Element>(
        template: LitHTMLRenderable,
        options?: FixtureOptions,
    ) => Promise<T>

    Renders a string or TemplateResult and puts it in the DOM via a fixtureWrapper.

    Uses fixture from @open-wc/testing-helpers.

    import {testWeb} from '@augment-vir/test';
    import {html} from 'element-vir';

    const rendered = await testWeb.render(html`
    <${MyElement}><span></span></${MyElement}>
    `);

    A Promise that will resolve to the first child of the rendered HTML.

  • typeIntoInput: (text: string, inputElement: Readonly<HTMLInputElement>) => Promise<void>

    Focus the given element and then type the given string.

  • typeText: (text: string) => Promise<void>

    Types the given string as if it were input by a keyboard. This doesn't try to type into any element in particular, it'll go wherever the current focus is, if any.