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

Relaxing element type definitions to HTMLElement #649

Merged
merged 6 commits into from Apr 19, 2021

Conversation

GreenGremlin
Copy link
Contributor

@GreenGremlin GreenGremlin commented Apr 12, 2021

Fixes #648

What: Relaxing element argument types to match the type returned by react-testing-library queries.

Why:

To allow user-event functions to be used with RTS queries without type casting.

How:

I'm narrowing the element type by checking that the passed elements are instances of valid element types. Thus, the check is runtime only, which makes sense since DOM queries are not fully type safe.

Checklist:

  • Documentation N/A
  • Tests
  • Typings
  • Ready to be merged

@codesandbox-ci
Copy link

codesandbox-ci bot commented Apr 12, 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 c60735d:

Sandbox Source
userEvent-PR-template Configuration

@@ -235,3 +235,12 @@ test('input.files implements iterable', () => {

expect(Array.from(eventTargetFiles)).toEqual(files)
})

test('should give error if we are trying to call upload on an invalid element', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty much just a copy / paste from the existing test in paste.js.

@codecov
Copy link

codecov bot commented Apr 12, 2021

Codecov Report

Merging #649 (c60735d) into master (5e6d7db) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #649   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           50        50           
  Lines          922       930    +8     
  Branches       363       366    +3     
=========================================
+ Hits           922       930    +8     
Impacted Files Coverage Δ
src/paste.ts 100.00% <100.00%> (ø)
src/upload.ts 100.00% <100.00%> (ø)
src/utils/edit/isEditable.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 5e6d7db...c60735d. Read the comment docs.

Copy link
Member

@ph-fritsche ph-fritsche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking the time to contribute. ❤️

src/paste.ts Outdated Show resolved Hide resolved
src/paste.ts Outdated Show resolved Hide resolved
src/upload.ts Outdated Show resolved Hide resolved
src/upload.ts Outdated Show resolved Hide resolved
src/paste.ts Outdated Show resolved Hide resolved
Copy link
Member

@ph-fritsche ph-fritsche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've opened a PR with code suggestions at GreenGremlin#1

fix: guard against unsupported elements
@GreenGremlin
Copy link
Contributor Author

@ph-fritsche thanks! I've merged your changes.

@ph-fritsche ph-fritsche merged commit dc13160 into testing-library:master Apr 19, 2021
@ph-fritsche
Copy link
Member

@all-contributors add @GreenGremlin code

@allcontributors
Copy link
Contributor

@ph-fritsche

I've put up a pull request to add @GreenGremlin! 🎉

@github-actions
Copy link

🎉 This PR is included in version 13.1.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

@GreenGremlin
Copy link
Contributor Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

User event element types are more narrow than what is returned by RTS queries
2 participants