import React from "react";
import { render, cleanup, fireEvent } from "@testing-library/react";
import "@testing-library/jest-dom/extend-expect";
import userEvent from "../../src";
afterEach(cleanup);
describe("userEvent.selectOptions", () => {
it.each(["select", "select multiple"])(
"should fire the correct events for <%s>",
type => {
const events = [];
const eventsHandler = jest.fn(evt => events.push(evt.type));
const multiple = type === "select multiple";
const eventHandlers = {
onMouseOver: eventsHandler,
onMouseMove: eventsHandler,
onMouseDown: eventsHandler,
onFocus: eventsHandler,
onMouseUp: eventsHandler,
onClick: eventsHandler
};
const { getByTestId } = render(
);
userEvent.selectOptions(getByTestId("element"), "1");
expect(events).toEqual([
"mouseover",
"mousemove",
"mousedown",
"focus",
"mouseup",
"click",
"mouseover", // The events repeat because we click on the child OPTION too
"mousemove", // But these specifically are the events bubbling up to the