Skip to content

Commit 3787d5a

Browse files
committed
When no argument is passed to the .click interaction command, the webdriver command should also have no argument
Indeed webdriver.io has a different behavior when the argument is not undefined. Fixes #8931
1 parent 1f73037 commit 3787d5a

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

packages/browser-webdriverio/src/commands/click.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import type { UserEventCommand } from './utils'
44
export const click: UserEventCommand<UserEvent['click']> = async (
55
context,
66
selector,
7-
options = {},
7+
options,
88
) => {
99
const browser = context.browser
10-
await browser.$(selector).click(options as any)
10+
await browser.$(selector).click(options)
1111
}
1212

1313
export const dblClick: UserEventCommand<UserEvent['dblClick']> = async (
1414
context,
1515
selector,
16-
_options = {},
16+
_options,
1717
) => {
1818
const browser = context.browser
1919
await browser.$(selector).doubleClick()
@@ -22,7 +22,7 @@ export const dblClick: UserEventCommand<UserEvent['dblClick']> = async (
2222
export const tripleClick: UserEventCommand<UserEvent['tripleClick']> = async (
2323
context,
2424
selector,
25-
_options = {},
25+
_options,
2626
) => {
2727
const browser = context.browser
2828
await browser

packages/browser/src/client/tester/locators/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@ export abstract class Locator {
7474
})
7575
}
7676

77-
public click(options: UserEventClickOptions = {}): Promise<void> {
77+
public click(options?: UserEventClickOptions): Promise<void> {
7878
return this.triggerCommand<void>('__vitest_click', this.selector, options)
7979
}
8080

81-
public dblClick(options: UserEventClickOptions = {}): Promise<void> {
81+
public dblClick(options?: UserEventClickOptions): Promise<void> {
8282
return this.triggerCommand<void>('__vitest_dblClick', this.selector, options)
8383
}
8484

85-
public tripleClick(options: UserEventClickOptions = {}): Promise<void> {
85+
public tripleClick(options?: UserEventClickOptions): Promise<void> {
8686
return this.triggerCommand<void>('__vitest_tripleClick', this.selector, options)
8787
}
8888

test/browser/test/userEvent.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,21 @@ describe('userEvent.click', () => {
2323
document.body.appendChild(button)
2424
const onClick = vi.fn()
2525
const dblClick = vi.fn()
26+
const onContextmenu = vi.fn()
2627
button.addEventListener('click', onClick)
28+
button.addEventListener('dblclick', onClick)
29+
button.addEventListener('contextmenu', onContextmenu)
2730

2831
await userEvent.click(button)
2932

3033
expect(onClick).toHaveBeenCalled()
3134
expect(dblClick).not.toHaveBeenCalled()
35+
expect(onContextmenu).not.toHaveBeenCalled()
36+
37+
onClick.mockClear()
38+
await userEvent.click(button, { button: 'right' })
39+
expect(onClick).not.toHaveBeenCalled()
40+
expect(onContextmenu).toHaveBeenCalled()
3241
})
3342

3443
test('correctly doesn\'t click on a disabled button', async () => {

0 commit comments

Comments
 (0)