diff --git a/test/browser/fixtures/user-event/pointer.test.ts b/test/browser/fixtures/user-event/pointer.test.ts index 1b053deac..ff86d5c19 100644 --- a/test/browser/fixtures/user-event/pointer.test.ts +++ b/test/browser/fixtures/user-event/pointer.test.ts @@ -131,7 +131,7 @@ test.fails('double clicks', async ({ expect }) => { expect(doubleClick).toHaveBeenCalledOnce() }) -test('middle click', async ({ expect }) => { +test('clicks with middle button', async ({ expect }) => { document.body.innerHTML = `` const down = vi.fn() @@ -157,6 +157,35 @@ test('middle click', async ({ expect }) => { expect(click).not.toHaveBeenCalled() }) +test('clicks with right button', async ({ expect }) => { + document.body.innerHTML = `` + + const down = vi.fn() + const up = vi.fn() + const click = vi.fn() + + const buttonElement = document.body.querySelector('button') + + buttonElement.addEventListener('mousedown', down) + buttonElement.addEventListener('mouseup', up) + buttonElement.addEventListener('click', click) + document.addEventListener('contextmenu', e => e.preventDefault()); + + const target = page.getByRole('button') + + await userEvent.pointer([ + { target, button: 'right', action: 'click' }, + ]) + + expect(down).toHaveBeenCalledExactlyOnceWith(expect.objectContaining({ + button: 2, + })) + expect(up).toHaveBeenCalledExactlyOnceWith(expect.objectContaining({ + button: 2, + })) + expect(click).not.toHaveBeenCalled() +}) + test('drags and drops', async ({ expect }) => { document.body.innerHTML = `
Drag me
@@ -276,40 +305,3 @@ test('modifiers work with coordinates', async ({ expect }) => { clientY: expect.closeTo(11), })) }) - -// on webkit, right click opens the context menu even in headless -// keep as the last test to prevent failing tests -test('right click', async ({ expect }) => { - document.body.innerHTML = `` - - const down = vi.fn() - const up = vi.fn() - const click = vi.fn() - - const buttonElement = document.body.querySelector('button') - - buttonElement.addEventListener('mousedown', down) - buttonElement.addEventListener('mouseup', up) - buttonElement.addEventListener('click', click) - - const target = page.getByRole('button') - - await userEvent.pointer([ - { target, button: 'right', action: 'click' }, - ]) - - expect(down).toHaveBeenCalledExactlyOnceWith(expect.objectContaining({ - button: 2, - })) - - // mouseup is not fired on webkit when right clicking - if (server.config.browser.name === 'webkit') { - expect(up).not.toHaveBeenCalled() - } else { - expect(up).toHaveBeenCalledExactlyOnceWith(expect.objectContaining({ - button: 2, - })) - } - - expect(click).not.toHaveBeenCalled() -})