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!: replace userEvent.paste #785

Merged
merged 2 commits into from Nov 17, 2021
Merged

feat!: replace userEvent.paste #785

merged 2 commits into from Nov 17, 2021

Conversation

ph-fritsche
Copy link
Member

@ph-fritsche ph-fritsche commented Nov 16, 2021

BREAKING CHANGE: The userEvent.paste API has new parameters.

What:

Replace userEvent.paste(element, text, init, options) API with:

userEvent.paste('textToBePasted')
userEvent.paste(clipboardData) // DataTransfer object
userEvent.paste() // Read from Clipboard API

Why:

Closes #782

How:

Implement logic as outlined in #782
This includes workarounds for the missing APIs in Jsdom.

userEvent.setup() replaces window.navigator.clipboard as the API is not available outside of secure context.
Uses DataTransfer and ClipboardItem if available, otherwise(Jsdom) it comes with stubs implementing most features.

A second parameter options exist to allow the usage on documents that are not global.document.

userEvent.paste(data, {document: myDocument})
userEvent.setup({document: myDocument}).paste(data) // or per setup

Checklist:

  • Documentation
  • Tests
  • Ready to be merged

BREAKING CHANGE: The `userEvent.paste` API has new parameters.
@ph-fritsche ph-fritsche added this to the userEvent v14 milestone Nov 16, 2021
@codesandbox-ci
Copy link

codesandbox-ci bot commented Nov 16, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 3e0c5a3:

Sandbox Source
userEvent-PR-template Configuration

@codecov
Copy link

codecov bot commented Nov 16, 2021

Codecov Report

Merging #785 (3e0c5a3) into alpha (051fe20) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             alpha      #785    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           64        68     +4     
  Lines         1387      1539   +152     
  Branches       542       580    +38     
==========================================
+ Hits          1387      1539   +152     
Impacted Files Coverage Δ
src/paste.ts 100.00% <100.00%> (ø)
src/setup.ts 100.00% <100.00%> (ø)
src/utils/dataTransfer/Blob.ts 100.00% <100.00%> (ø)
src/utils/dataTransfer/Clipboard.ts 100.00% <100.00%> (ø)
src/utils/dataTransfer/DataTransfer.ts 100.00% <100.00%> (ø)
src/utils/dataTransfer/FileList.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 051fe20...3e0c5a3. Read the comment docs.

@ph-fritsche ph-fritsche marked this pull request as ready for review November 16, 2021 20:27
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.

Redefine userEvent.paste behavior Support contenteditable divs with userEvent.paste
1 participant