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>(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.

      • (): void
      • Cleans up all defined fixtures by removing the actual wrapper nodes. Common usecase is at the end of each test.

        Returns void

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

    Clicks the center of the given element.

      • (element): Promise<void>
      • Parameters

        • element: Element

        Returns Promise<void>

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

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

      • (inputElement): Promise<void>
      • Parameters

        • inputElement: Readonly<HTMLInputElement>

        Returns Promise<void>

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

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

      • (element, maxAttemptCount?): Promise<void>
      • Parameters

        • element: Element
        • maxAttemptCount: number = 20

        Returns Promise<void>

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

    Moves the mouse to the center of the given element.

      • (element): Promise<void>
      • Parameters

        • element: Element

        Returns Promise<void>

  • render: (<T>(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.

      • <T>(template, options?): Promise<T>
      • Renders a string/TemplateResult and puts it in the DOM via a fixtureWrapper. By default fixture awaits the elements "update complete" Promise.

        If none of those specfic Promise hooks are found, it will wait for one frame via await nextFrame().

        Note: this does not guarantee that the element is done rendering - it just waits for the next JavaScript tick.

        Type Parameters

        • T extends Element

        Parameters

        • template: LitHTMLRenderable

          Either a string or lit-html TemplateResult

        • Optionaloptions: FixtureOptions

        Returns Promise<T>

        A Promise that will resolve to the first child of the rendered DOM

        const el = await fixture('<my-el><span></span></my-el>');
        expect(el.fullyRendered).to.be.true;
  • typeIntoInput: ((text: string, inputElement: Readonly<HTMLInputElement>) => Promise<void>)

    Focus the given element and then type the given string.

      • (text, inputElement): Promise<void>
      • Parameters

        • text: string
        • inputElement: Readonly<HTMLInputElement>

        Returns Promise<void>

  • 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.

      • (text): Promise<void>
      • Parameters

        • text: string

        Returns Promise<void>