diff --git a/README.md b/README.md index 64b5d088..e2e5db3f 100644 --- a/README.md +++ b/README.md @@ -52,8 +52,8 @@ change the state of the checkbox. - [Installation](#installation) - [API](#api) - - [`click(element)`](#clickelement) - - [`dblClick(element)`](#dblclickelement) + - [`click(element, eventInit, options)`](#clickelement-eventinit-options) + - [`dblClick(element, eventInit, options)`](#dblclickelement-eventinit-options) - [`async type(element, text, [options])`](#async-typeelement-text-options) - [`upload(element, file, [{ clickInit, changeInit }])`](#uploadelement-file--clickinit-changeinit-) - [`clear(element)`](#clearelement) @@ -95,7 +95,7 @@ var userEvent = require('@testing-library/user-event') ## API -### `click(element)` +### `click(element, eventInit, options)` Clicks `element`, depending on what `element` is it can have different side effects. @@ -128,7 +128,10 @@ See the [`MouseEvent`](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent) constructor documentation for more options. -### `dblClick(element)` +Note that `click` will trigger hover events before clicking. To disable this, +set the `skipHover` option to `true`. + +### `dblClick(element, eventInit, options)` Clicks `element` twice, depending on what `element` is it can have different side effects. @@ -169,6 +172,9 @@ test('type', async () => { are typed. By default it's 0. You can use this option if your component has a different behavior for fast or slow users. +`type` will click the element before typing. To disable this, set the +`skipClick` option to `true`. + #### Special characters The following special character strings are supported: @@ -187,7 +193,9 @@ The following special character strings are supported: > **A note about modifiers:** Modifier keys (`{shift}`, `{ctrl}`, `{alt}`, > `{meta}`) will activate their corresponding event modifiers for the duration -> of type command or until they are closed (via `{/shift}`, `{/ctrl}`, etc.). +> of type command or until they are closed (via `{/shift}`, `{/ctrl}`, etc.). If +> they are not closed explicitly, then events will be fired to close them +> automatically (to disable this, set the `skipAutoClose` option to `true`). diff --git a/typings/index.d.ts b/typings/index.d.ts index 9f70f21f..59a42015 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1,5 +1,7 @@ // Definitions by: Wu Haotian export interface ITypeOpts { + skipClick?: boolean + skipAutoClose?: boolean delay?: number initialSelectionStart?: number initialSelectionEnd?: number @@ -19,10 +21,23 @@ export type UploadInitArgument = { changeInit?: Event } +export interface IClickOptions { + skipHover?: boolean + clickCount?: number +} + declare const userEvent: { clear: (element: TargetElement) => void - click: (element: TargetElement, init?: MouseEventInit) => void - dblClick: (element: TargetElement, init?: MouseEventInit) => void + click: ( + element: TargetElement, + init?: MouseEventInit, + options?: IClickOptions, + ) => void + dblClick: ( + element: TargetElement, + init?: MouseEventInit, + options?: IClickOptions, + ) => void selectOptions: ( element: TargetElement, values: string | string[] | HTMLElement | HTMLElement[],