Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test] Allow to pass options to mousePress function #34124

Merged
merged 1 commit into from Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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