I'm trying to paste text that's already in my clipboard into a textbox, but I dont understand how to use "eventInit" to do this. I've read the documentation on how to paste text into a textbox, but it isn't clear on how to use eventInit.
How do i paste text that's in my clipboard into a textbox using userEvent?
This is my code:
test('Copy id button copies correct id', async () => {
const { getAllByLabelText, debug, getByText } = render(
<MockedProvider mocks={mocks} addTypename={false}>
<History />
</MockedProvider>
);
const textbox = <input type="text" />;
await waitFor(() => new Promise((resolve) => setTimeout(resolve, 0)));
const button = getAllByLabelText('click to copy id')[0];
fireEvent.click(button);
// userEvent.paste(textbox,_,) unsure what to do here...
});
copy to clipboard
code? – TelescopeuserEvent.paste(getByRole('textbox', { name: /paste your greeting/i }), text)
means mocking your clipboard text in to the targeted textbox. After this paste action you can just check the content of targeted textbox has the mocked text. – Desalvo