@tigerface/lwc-test-utils
    Preparing search index...

    Class Simulate

    A class containing helper functions for actions that a user would normally perform such as typing into an input field or clicking keyboard keys.

    Index

    Constructors

    Methods

    • Simulate a user changing the value of a checkbox

      Parameters

      • checkboxEl: HTMLInputElement

        the checkbox element

      • value: boolean

        the updated value

      Returns void

       // simulate checkbox getting checked
      Simulate.checkboxChange(checkboxEl, true);
    • Dispatches an event from an element.

      Parameters

      • element: Document | HTMLElement | Window

        the element to dispatch the event from

      • eventName: string

        the name of the event

      • Optionalpayload: CustomEventInit<any>

        the payload of the event

      Returns void

       // simulate a custom event
      Simulate.event(menuEl, 'select', { detail: { value: 'clip' } });
    • Simulate a user changing the value of an input element

      Parameters

      • inputEl: HTMLInputElement

        the input element

      • value: string

        the updated value

      Returns void

       // simulate input changing to hello world
      Simulate.inputChange(inputEl, 'hello world');
    • Simulate a keyboard event

      Parameters

      • element: Document | HTMLElement | Window

        the element to trigger the event

      • event: "keydown" | "keypress" | "keyup"

        the name of the keyboard event (Ex: keyup)

      • payload: KeyboardEventInit

        the payload of the event

      Returns void

       // simulate enter key press
      Simulate.keyboardEvent(inputEl, 'keyup', { key: 'Enter' });
    • Simulate a user pressing a key on the supplied element

      Parameters

      Returns void

      since version 0.0.4 Use keyEvent instead. Will be removed in version 1.0.

    • Simulate a mouse event

      Parameters

      • element: Document | HTMLElement | Window

        the element to click

      • event: string

        the name of the mouse event (Ex: click, dblclick, mouseup, mousemove, mousedown)

      • payload: MouseEventInit

        the payload of the event

      Returns void

       // simulate mouse move event
      Simulate.mouseEvent(document, 'mousemove', { clientX: 150 });