cyb*_*lot 2 javascript testing-library
在 @testing-library/user-event 13 中,这有点微不足道:
paste(element, text, eventInit, options);
Run Code Online (Sandbox Code Playgroud)
然而,在 14 中,添加了复制和剪切,现在需要某种指针选择,从文档中尚不清楚它现在应该如何工作。我尝试研究该库的测试以了解它是如何使用的,但测试依赖于私有设置,这使得更难了解这种情况下具体需要什么。
就我的问题而言,如何将粘贴示例从 @testing-library/user-event 13 移植到 @testing-library/user-event 14 中?
如果您首先单击该元素,然后粘贴,它应该可以工作。
改编 v13 示例:
test('should paste text in input', async() => {
render(<MyInput />)
const text = 'Hello, world!'
const element = screen.getByRole('textbox', {name: /paste your greeting/i})
await userEvent.click(element)
await userEvent.paste(text)
expect(element).toHaveValue(text)
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2020 次 |
| 最近记录: |