简体   繁体   English

React testing-library 模拟触摸和移动,指针的键是什么?

[英]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.触摸指针仅在触摸屏幕时存在,并且每次都会收到一个新的 pointerId。 For these pointers, we use the "button" name from the press action as pointerName.对于这些指针,我们使用来自按下动作的“按钮”名称作为 pointerName。

https://testing-library.com/docs/user-event/pointer#moving-a-pointer 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 ?为什么键名TouchA中有一个A and should the following pointerName use the same name as the key name?下面的pointerName是否应该使用与键名相同的名称? 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.根据文档,指针 API 允许模拟与指针设备的交互。 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.所以基本上,当您在元素 1 上触摸屏幕时,我们会分配指针 Input touchA 并且目标是 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.当我们将相同的触摸点移动到 element2 时,这意味着指针名称是相同的 touchA 但目标更改为 element2 并且当触摸结束时使用 [/TouchA] 。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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