Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: user event paste #1646

Merged
merged 3 commits into from
Aug 16, 2024
Merged

feat: user event paste #1646

merged 3 commits into from
Aug 16, 2024

Conversation

mdjastrzebski
Copy link
Member

@mdjastrzebski mdjastrzebski commented Aug 13, 2024

Summary

User Event paste() function with following signature:

function paste(element: ReactTestInstance, text: string);

This function simulates user interaction when user focuses a text input, (select all text if present), pastes given text, and finally leaves the text input.

In the basic for no options are accepted but if needed, they might be added in a future PRs.

Experimental event sequence.

Details

The signature of the function is based on User Event v13 variant: paste(element, dataOrText) and not User Event v14 variant: paste(dataOrText).

Although we generally subscribe to v14 API convention, however there were two issues with it:

  1. More difficult API:
const element = screen.getByRole('textbox', {name: /paste your greeting/i})
await userEvent.click(element) // This focuses the element 
await userEvent.paste(text) // This pastes to the current element

Many users complained about the modified API or found it confusing: orig UE issue (4 negative votes), UE PR (11 negative votes), SO issue, UE issue.

  1. RNTL currently does not maintain any runtime state of elements, like currently focused element, which would be required to implement v14 approach. Implementing such "runtime state" API, while possible would require breaking changes to do properly.

Test plan

Confirm experimental behavior using automated tests.

@mdjastrzebski mdjastrzebski merged commit 38bceed into main Aug 16, 2024
7 checks passed
@mdjastrzebski mdjastrzebski deleted the feat/user-event-paste branch August 16, 2024 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant