Skip to content

Commit

Permalink
[test] Allow to pass options to mousePress function (#34124)
Browse files Browse the repository at this point in the history
  • Loading branch information
cherniavskii committed Aug 30, 2022
1 parent 2fdf868 commit b8b76fb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions test/utils/fireDiscreteEvent.js
Expand Up @@ -45,9 +45,9 @@ function withMissingActWarningsIgnored(callback) {
// Note that using `fireEvent` from `@testing-library/dom` would not work since /react configures both `fireEvent` to use `act` as a wrapper.
// -----------------------------------------

export function click(element) {
export function click(element, options) {
return withMissingActWarningsIgnored(() => {
fireEvent.click(element);
fireEvent.click(element, options);
});
}

Expand All @@ -74,7 +74,7 @@ export function keyUp(element, options) {
}

/**
* @param {Element} element
* @param {Element | Node | Document | Window} element
* @param {{}} [options]
* @returns {void}
*/
Expand All @@ -85,7 +85,7 @@ export function mouseDown(element, options) {
}

/**
* @param {Element} element
* @param {Element | Node | Document | Window} element
* @param {{}} [options]
* @returns {void}
*/
Expand Down
18 changes: 9 additions & 9 deletions test/utils/userEvent.ts
@@ -1,24 +1,24 @@
import * as React from 'react';
import { click, mouseDown, mouseUp, keyDown, keyUp } from './fireDiscreteEvent';
import { act, fireEvent } from './createRenderer';
import { act, fireEvent, FireFunction } from './createRenderer';

export function touch(target: Element): void {
fireEvent.touchStart(target);
fireEvent.touchEnd(target);
}

export function mousePress(target: Element): void {
export const mousePress: (...args: Parameters<FireFunction>) => void = (target, options) => {
if (React.version.startsWith('18')) {
fireEvent.mouseDown(target);
fireEvent.mouseUp(target);
fireEvent.click(target);
fireEvent.mouseDown(target, options);
fireEvent.mouseUp(target, options);
fireEvent.click(target, options);
} else {
mouseDown(target);
mouseUp(target);
click(target);
mouseDown(target, options);
mouseUp(target, options);
click(target, options);
act(() => {});
}
}
};

export function keyPress(target: Element, options: { key: string }): void {
if (React.version.startsWith('18')) {
Expand Down

0 comments on commit b8b76fb

Please sign in to comment.