import { render, cleanup } from "@testing-library/vue"; import "@testing-library/jest-dom/extend-expect"; import userEvent from "../../src"; afterEach(cleanup); describe("userEvent.click", () => { it.each(["input", "textarea"])( "should fire the correct events for <%s>", type => { const events = []; const eventsHandler = jest.fn(evt => events.push(evt.type)); const { getByTestId } = render({ render: function(h) { return h(type, { attrs: { "data-testid": "element" }, on: { mouseover: eventsHandler, mousemove: eventsHandler, mousedown: eventsHandler, focus: eventsHandler, mouseup: eventsHandler, click: eventsHandler } }); } }); userEvent.click(getByTestId("element")); // baseElement is always
, si wasAnotherElementFocused is false expect(events).toEqual([ "mouseover", "mousemove", "mousedown", "focus", "mouseup", "click" ]); } ); it('should fire the correct events for ', () => { const events = []; const eventsHandler = jest.fn(evt => events.push(evt.type)); const { getByTestId } = render({ render: function(h) { return h("input", { attrs: { type: "checkbox", "data-testid": "element" }, on: { mouseover: eventsHandler, mousemove: eventsHandler, mousedown: eventsHandler, focus: eventsHandler, mouseup: eventsHandler, click: eventsHandler, change: eventsHandler } }); } }); userEvent.click(getByTestId("element")); expect(events).toEqual([ "mouseover", "mousemove", "mousedown", "mouseup", "click", "change" ]); expect(getByTestId("element")).toHaveProperty("checked", true); }); it('should fire the correct events for ', () => { const events = []; const eventsHandler = jest.fn(evt => events.push(evt.type)); const { getByTestId } = render({ render: function(h) { return h("input", { attrs: { type: "checkbox", "data-testid": "element", disabled: "disabled" }, on: { mouseover: eventsHandler, mousemove: eventsHandler, mousedown: eventsHandler, focus: eventsHandler, mouseup: eventsHandler, click: eventsHandler, change: eventsHandler } }); } }); userEvent.click(getByTestId("element")); expect(events).toEqual([]); expect(getByTestId("element")).toHaveProperty("checked", false); }); it('should fire the correct events for ', () => { const events = []; const eventsHandler = jest.fn(evt => events.push(evt.type)); const { getByTestId } = render({ render: function(h) { return h("input", { attrs: { type: "radio", "data-testid": "element" }, on: { mouseover: eventsHandler, mousemove: eventsHandler, mousedown: eventsHandler, focus: eventsHandler, mouseup: eventsHandler, click: eventsHandler, change: eventsHandler } }); } }); userEvent.click(getByTestId("element")); expect(events).toEqual([ "mouseover", "mousemove", "mousedown", "mouseup", "click", "change" ]); expect(getByTestId("element")).toHaveProperty("checked", true); }); it('should fire the correct events for ', () => { const events = []; const eventsHandler = jest.fn(evt => events.push(evt.type)); const { getByTestId } = render({ render: function(h) { return h("input", { attrs: { type: "radio", "data-testid": "element", disabled: "disabled" }, on: { mouseover: eventsHandler, mousemove: eventsHandler, mousedown: eventsHandler, focus: eventsHandler, mouseup: eventsHandler, click: eventsHandler, change: eventsHandler } }); } }); userEvent.click(getByTestId("element")); expect(events).toEqual([]); expect(getByTestId("element")).toHaveProperty("checked", false); }); it("should fire the correct events for