简体   繁体   中英

React testing-library to simulate touch and move, what is the key for a pointer?

I want to simulate a user touching an element and moving it. But I don't quite get what is document says.

A touch pointer only exists while the screen is touched and receives a new pointerId every time. For these pointers, we use the "button" name from the press action as pointerName.

https://testing-library.com/docs/user-event/pointer#moving-a-pointer

pointer([
  // touch the screen at element1
  {keys: '[TouchA>]', target: element1},
  // move the touch pointer to element2
  {pointerName: 'TouchA', target: element2},
  // release the touch pointer at the last position (element2)
  {keys: '[/TouchA]'},
])

Why there is an A in the key name TouchA ? and should the following pointerName use the same name as the key name? Can I use other names for simulating a "touch and move" behavior?

As per documentation, The pointer API allows to simulate interactions with pointer devices. As of now, supported pointer devices are mouse and touch and following pointer input keys are supported

yes, following pointer name would be following the same key name. So basically, when you touch a screen on element one then we assign pointer Input touchA and target is element1. When we move same touch point to element2 which means the pointer name is same touchA but the target is changed to element2 and when the touch ends then [/TouchA] is used.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM