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(ByAltText): Always include custom elements #1049

Merged
merged 3 commits into from
Oct 6, 2021

Conversation

SantoJambit
Copy link
Contributor

@SantoJambit SantoJambit commented Oct 5, 2021

What: Made the ByAltText methods tag-agnostic

Why: ByAltText does currently not support <amp-img> (and possibly other custom-elements).

How: by using the existing queryAllByAttribute function and thus dropping the limitation to only 'img,input,area' tags.

Checklist:

Note:
queryAllByAltText and queryAllByAttribute are mostly identical, so I chose to just call queryAllByAttribute.
However queryAllByAltText had an additional call to checkContainerType, which I left in place. Not sure why queryAllByAttribute does not have this check.

Alternatively, I could leave the old logic in place and simply add the tag amp-img to the allowed list, but I think this way is better.

I will create an update PR for the docs when it's clear, that this will be merged.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Oct 5, 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 3536716:

Sandbox Source
react-testing-library-examples Configuration

@SantoJambit
Copy link
Contributor Author

Sorry, there was a mixup on who was supposed to create a PR for this issue.. feel free to choose between this and #1048

).filter(node =>
matcher(node.getAttribute('alt'), node, alt, matchNormalizer),
)
return queryAllByAttribute('alt', container, alt, options)
Copy link
Member

Choose a reason for hiding this comment

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

If this PR only targets custom elements then let's restrict it to known and custom elements. Otherwise <p alt /> becomes queryable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added a filter.

@codecov
Copy link

codecov bot commented Oct 5, 2021

Codecov Report

Merging #1049 (3536716) into main (b28586e) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##              main     #1049   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           25        25           
  Lines          920       919    -1     
  Branches       284       283    -1     
=========================================
- Hits           920       919    -1     
Flag Coverage Δ
node-12 100.00% <100.00%> (ø)
node-14 100.00% <100.00%> (ø)
node-16.9.1 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/queries/alt-text.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 b28586e...3536716. Read the comment docs.

Copy link
Member

@eps1lon eps1lon left a comment

Choose a reason for hiding this comment

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

Do we have a test that e.g. <div alt /> is not queried? If not then we should add one now that the behavior is not trivial anymore.

Copy link
Member

@eps1lon eps1lon left a comment

Choose a reason for hiding this comment

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

Looks clean, great job.

src/queries/alt-text.ts Show resolved Hide resolved
@eps1lon
Copy link
Member

eps1lon commented Oct 6, 2021

@SantoJambit Could you review the docs change testing-library/testing-library-docs#946 ?

@eps1lon eps1lon added the enhancement New feature or request label Oct 6, 2021
@eps1lon eps1lon changed the title feat: Support all tags for alt-text feat(ByAltText): Always include custom elements Oct 6, 2021
@SantoJambit
Copy link
Contributor Author

@eps1lon thanks for the review and the docs PR. I've reviewed the docs PR.

@eps1lon eps1lon merged commit 87d2682 into testing-library:main Oct 6, 2021
@eps1lon
Copy link
Member

eps1lon commented Oct 6, 2021

@all-contributors add @SantoJambit for code

@allcontributors
Copy link
Contributor

@eps1lon

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

@SantoJambit SantoJambit deleted the pr/alt-tag branch October 7, 2021 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants