包详细信息

@heartlandone/vega-testing-library

heartlandpayments149UNLICENSED0.6.0

A lightweight testing utility that extends @testing-library/user-event to seamlessly simulate user interactions with Vega Web Components.

自述文件

vega-testing-library

What is userEvent api

user-event is a companion library for Testing Library that simulates user interactions by dispatching the events that would happen if the interaction took place in a browser

Why we need to extending user event api

Currently, when using the test library for interactive operations, it becomes very troublesome and cumbersome to find triggerable elements because Shadow DOM is used

const shadowInput: Element = document
.querySelector("vega-input")
?.shadowRoot?.querySelector("input") as Element;

userEvent.type(shadowInput, "input text");

When should use this library

Components that involve user interaction should all use this library to simplify operations and make user events simple and efficient.

Usage

import userEvent from '@testing-library/user-event';
import { createUserEventForVega } from '@heartlandone/vega-testing-library';

let user = userEvent.setup();

const userEvent = createUserEventForVega(user);
userEvent.type('vega-input', 'input text');
....

Supported Components

Component Name User Event API supported
vega-button click: simulates a user clicking on the button
hover: simulates a user hovering their pointer over the button
unhover: simulates a user moving their pointer away from the button
vega-button-circle click: simulates a user clicking on the button circle
hover: simulates a user hovering their pointer over the button circle
unhover: simulates a user moving their pointer away from the button circle
vega-button-link click: simulates a user clicking on the button link
hover: simulates a user hovering their pointer over the button link
unhover: simulates a user moving their pointer away from the button link
vega-checkbox click: simulates a user clicking on the checkbox
hover: simulates a user hovering their pointer over the checkbox
unhover: simulates a user moving their pointer away from the checkbox
vega-file-uploader clear: simulates a user clearing the value of the file uploader
upload: simulates a user uploading files to the file uploader
vega-input clear: simulates a user clearing the value of the input
click: simulates a user clicking on the input
type: simulates a user typing text into the input
vega-input-numeric clear: simulates a user clearing the value of the input numeric
click: simulates a user clicking on the input numeric
type: simulates a user typing text into the input numeric
vega-input-select deselectOptions: simulates a user deselecting options from a multi-select
selectOptions: simulates a user selecting options from a select
type: simulates a user typing text into the input select
vega-radio click: simulates a user clicking on the radio
hover: simulates a user hovering their pointer over the radio
unhover: simulates a user moving their pointer away from the radio