javascriptreactjsreact-testing-librarytesting-libraryuser-event

Cannot produce element right-click in react testing-library user-event v14


I'm using react-contextmenu and I was able to trigger contextmenu in v13 by following

userEvent.click(node, { button: 2 });

but after upgrading v14 I'm not able to trigger contextmenu or right-click event of an element

Tried fireEvent.contextMenu(node) and various ways but didn't work.


Solution

  • Bit of a longshot but try changing to the newer API:

      userEventuser.pointer({ keys: '[MouseRight>]', target: node })