testing-library / dom-testing-library

🐙 Simple and complete DOM testing utilities that encourage good testing practices.
https://testing-library.com/dom
MIT License
3.26k stars 466 forks source link

feat(ByRole): Allow filter by value state #1223

Closed eps1lon closed 1 year ago

eps1lon commented 1 year ago

Part of a larger committment to unify APIs for /react-native and /react (which is just /react-dom at the moment)

What:

Enables ByRole(role, { value })

Note that we don't support valuenow but rather value.now (same pattern for other aria-value* attributes). One reason is parity with @testing-library/react-native.

The other reason is that value.* works a bit different in that it looks at all value.* and combines them with && instead of returning on the first match. Today, { pressed: true, selected: true} has kind of an odd behavior since it only looks at whatever comes first in the implementation. We could combine them with && as well but it's not clear to me yet that this is always good. So by putting them in a single object makes it clear that we look at the whole object which wouldn't be that obvious for { name, valuemin, valuemax}. I don't feel too strongly about this specific rationale. I care more about parity with /react-native.

Why:

Makes writing tests for react-native and react-dom easier by removing barriers when changing the target platform that's being tested.

How:

Same patterns as for expanded, selected etc

Checklist:

codesandbox-ci[bot] commented 1 year ago

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 c9a2416252660eeeeacb7d4b3fa1c89cb9825d5e:

Sandbox Source
react-testing-library-examples Configuration
codecov[bot] commented 1 year ago

Codecov Report

Merging #1223 (daf92b3) into main (8c40a21) will not change coverage. The diff coverage is 100.00%.

:exclamation: Current head daf92b3 differs from pull request most recent head c9a2416. Consider uploading reports for the commit c9a2416 to get more accurate results

@@            Coverage Diff            @@
##              main     #1223   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           24        24           
  Lines          999      1035   +36     
  Branches       323       346   +23     
=========================================
+ Hits           999      1035   +36     
Flag Coverage Δ
node-14 100.00% <100.00%> (ø)
node-16 100.00% <100.00%> (ø)
node-18 100.00% <100.00%> (ø)

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

Impacted Files Coverage Δ
src/queries/role.ts 100.00% <100.00%> (ø)
src/role-helpers.js 100.00% <100.00%> (ø)

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more