admin管理员组文章数量:1334887
In @testing-library/user-event 13, it was sort of trivial with:
paste(element, text, eventInit, options);
However, in 14, copy and cut was added and past now requires some kind of pointer selection which is not clear from the documentation how it should work now. I have tried looking into the library's tests to see how it is used, but tests rely on a private setup that makes it harder to see what's needed for this case in specific.
To the point of my question, how one would port the paste example from @testing-library/user-event 13 into @testing-library/user-event 14?
In @testing-library/user-event 13, it was sort of trivial with:
paste(element, text, eventInit, options);
However, in 14, copy and cut was added and past now requires some kind of pointer selection which is not clear from the documentation how it should work now. I have tried looking into the library's tests to see how it is used, but tests rely on a private setup that makes it harder to see what's needed for this case in specific.
To the point of my question, how one would port the paste example from @testing-library/user-event 13 into @testing-library/user-event 14?
Share Improve this question asked Dec 12, 2022 at 13:46 cyberglotcyberglot 3954 silver badges34 bronze badges1 Answer
Reset to default 8It should work if you first click the element, then paste.
Adapting the v13 example:
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)
})
本文标签: javascriptHow to copypaste in testinglibraryuserevent 14Stack Overflow
版权声明:本文标题:javascript - How to copypaste in @testing-libraryuser-event 14? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742330828a2454659.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论