(
user: {
click: (element: Element) => Promise<void>;
keyboard: (keys: string) => Promise<void>;
pointer: (opts: {target: Element; keys: string; coords?: any}) => Promise<void>;
},
element: HTMLElement,
interactionType: UserOpts['interactionType']
)
| 135 | |
| 136 | // Docs cannot handle the types that userEvent actually declares, so hopefully this sub set is okay |
| 137 | export async function pressElement( |
| 138 | user: { |
| 139 | click: (element: Element) => Promise<void>; |
| 140 | keyboard: (keys: string) => Promise<void>; |
| 141 | pointer: (opts: {target: Element; keys: string; coords?: any}) => Promise<void>; |
| 142 | }, |
| 143 | element: HTMLElement, |
| 144 | interactionType: UserOpts['interactionType'] |
| 145 | ): Promise<void> { |
| 146 | if (interactionType === 'mouse') { |
| 147 | // Add coords with pressure so this isn't detected as a virtual click |
| 148 | await user.pointer({target: element, keys: '[MouseLeft]', coords: {pressure: 0.5}}); |
| 149 | } else if (interactionType === 'keyboard') { |
| 150 | act(() => element.focus()); |
| 151 | await user.keyboard('[Space]'); |
| 152 | } else if (interactionType === 'touch') { |
| 153 | await user.pointer({target: element, keys: '[TouchA]'}); |
| 154 | } |
| 155 | } |
no test coverage detected