Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: testing-library/jest-dom
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v6.4.8
Choose a base ref
...
head repository: testing-library/jest-dom
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 62f0e3a43262b945bbf6bdd9bf231bf3e4ac7778
Choose a head ref
  • 6 commits
  • 6 files changed
  • 6 contributors

Commits on Jul 24, 2024

  1. chore: remove unused @babel/runtime dependency (#617)

    aleks-elkin authored Jul 24, 2024
    Copy the full SHA
    aa094a5 View commit details
  2. docs: add aleks-elkin as a contributor for maintenance (#618)

    * docs: update README.md
    
    * docs: update .all-contributorsrc
    
    ---------
    
    Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
    allcontributors[bot] authored Jul 24, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    a073b08 View commit details
  3. adjust vitest ambient declaration file according to vitest docs (#612)

    Co-authored-by: Ernesto García <ernesto@ernesto.dev>
    vorant94 and gnapse authored Jul 24, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    06d19ba View commit details
  4. docs: add vorant94 as a contributor for code (#619)

    * docs: update README.md
    
    * docs: update .all-contributorsrc
    
    ---------
    
    Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
    allcontributors[bot] authored Jul 24, 2024
    Copy the full SHA
    47a667c View commit details

Commits on Aug 23, 2024

  1. feat(toHaveValue): Asserting aria-valuenow (#479)

    Co-authored-by: Wayne Van Son <waynevanson@gmail.com>
    idanen and waynevanson authored Aug 23, 2024
    Copy the full SHA
    acbf416 View commit details
  2. docs: add waynevanson as a contributor for code, and test (#626)

    allcontributors[bot] authored Aug 23, 2024
    Copy the full SHA
    62f0e3a View commit details
Showing with 69 additions and 6 deletions.
  1. +28 −0 .all-contributorsrc
  2. +8 −0 README.md
  3. +0 −1 package.json
  4. +14 −0 src/__tests__/to-have-value.js
  5. +12 −2 src/utils.js
  6. +7 −3 types/vitest.d.ts
28 changes: 28 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
@@ -766,6 +766,34 @@
"contributions": [
"maintenance"
]
},
{
"login": "aleks-elkin",
"name": "Aleksandr Elkin",
"avatar_url": "https://avatars.githubusercontent.com/u/55530374?v=4",
"profile": "https://github.com/aleks-elkin",
"contributions": [
"maintenance"
]
},
{
"login": "vorant94",
"name": "Mordechai Dror",
"avatar_url": "https://avatars.githubusercontent.com/u/9719319?v=4",
"profile": "https://www.vorant94.io/",
"contributions": [
"code"
]
},
{
"login": "waynevanson",
"name": "Wayne Van Son",
"avatar_url": "https://avatars.githubusercontent.com/u/29592214?v=4",
"profile": "http://www.waynevanson.com",
"contributions": [
"code",
"test"
]
}
],
"repoHost": "https://github.com",
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -996,6 +996,9 @@ It accepts `<input>`, `<select>` and `<textarea>` elements with the exception of
matched only using [`toBeChecked`](#tobechecked) or
[`toHaveFormValues`](#tohaveformvalues).

It also accepts elements with roles `meter`, `progressbar`, `slider` or
`spinbutton` and checks their `aria-valuenow` attribute (as a number).

For all other form elements, the value is matched using the same algorithm as in
[`toHaveFormValues`](#tohaveformvalues) does.

@@ -1547,6 +1550,11 @@ Thanks goes to these people ([emoji key][emojis]):
<td align="center" valign="top" width="14.28%"><a href="https://github.com/tonyhallett"><img src="https://avatars.githubusercontent.com/u/11292998?v=4?s=100" width="100px;" alt="Tony Hallett"/><br /><sub><b>Tony Hallett</b></sub></a><br /><a href="https://github.com/testing-library/jest-dom/issues?q=author%3Atonyhallett" title="Bug reports">🐛</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/ddolcimascolo"><img src="https://avatars.githubusercontent.com/u/5468291?v=4?s=100" width="100px;" alt="David DOLCIMASCOLO"/><br /><sub><b>David DOLCIMASCOLO</b></sub></a><br /><a href="#maintenance-ddolcimascolo" title="Maintenance">🚧</a></td>
</tr>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/aleks-elkin"><img src="https://avatars.githubusercontent.com/u/55530374?v=4?s=100" width="100px;" alt="Aleksandr Elkin"/><br /><sub><b>Aleksandr Elkin</b></sub></a><br /><a href="#maintenance-aleks-elkin" title="Maintenance">🚧</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://www.vorant94.io/"><img src="https://avatars.githubusercontent.com/u/9719319?v=4?s=100" width="100px;" alt="Mordechai Dror"/><br /><sub><b>Mordechai Dror</b></sub></a><br /><a href="https://github.com/testing-library/jest-dom/commits?author=vorant94" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="http://www.waynevanson.com"><img src="https://avatars.githubusercontent.com/u/29592214?v=4?s=100" width="100px;" alt="Wayne Van Son"/><br /><sub><b>Wayne Van Son</b></sub></a><br /><a href="https://github.com/testing-library/jest-dom/commits?author=waynevanson" title="Code">💻</a> <a href="https://github.com/testing-library/jest-dom/commits?author=waynevanson" title="Tests">⚠️</a></td>
</tr>
</tbody>
</table>

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -81,7 +81,6 @@
"license": "MIT",
"dependencies": {
"@adobe/css-tools": "^4.4.0",
"@babel/runtime": "^7.9.2",
"aria-query": "^5.0.0",
"chalk": "^3.0.0",
"css.escape": "^1.5.1",
14 changes: 14 additions & 0 deletions src/__tests__/to-have-value.js
Original file line number Diff line number Diff line change
@@ -203,4 +203,18 @@ Received:
<red> foo</>
`)
})

test('handles value of aria-valuenow', () => {
const valueToCheck = 70
const {queryByTestId} = render(`
<div role="meter" aria-valuemin="0" aria-valuemax="100" aria-valuenow="${valueToCheck}" data-testid="meter"></div>
<div role="textbox" aria-valuenow="${valueToCheck}" data-testid="textbox"></div>
`)

expect(queryByTestId('meter')).toHaveValue(valueToCheck)
expect(queryByTestId('meter')).not.toHaveValue(valueToCheck + 1)

// Role that does not support aria-valuenow
expect(queryByTestId('textbox')).not.toHaveValue(70)
})
})
14 changes: 12 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -196,18 +196,28 @@ function getInputValue(inputElement) {
}
}

const rolesSupportingValues = ['meter', 'progressbar', 'slider', 'spinbutton']
function getAccessibleValue(element) {
if (!rolesSupportingValues.includes(element.getAttribute('role'))) {
return undefined
}
return Number(element.getAttribute('aria-valuenow'))
}

function getSingleElementValue(element) {
/* istanbul ignore if */
if (!element) {
return undefined
}

switch (element.tagName.toLowerCase()) {
case 'input':
return getInputValue(element)
case 'select':
return getSelectValue(element)
default:
return element.value
default: {
return element.value ?? getAccessibleValue(element)
}
}
}

10 changes: 7 additions & 3 deletions types/vitest.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import {type expect} from 'vitest'
import {type TestingLibraryMatchers} from './matchers'

export {}
declare module '@vitest/expect' {
interface JestAssertion<T = any>
declare module 'vitest' {
interface Assertion<T = any>
extends TestingLibraryMatchers<
ReturnType<typeof expect.stringContaining>,
T
> {}
interface AsymmetricMatchersContaining
extends TestingLibraryMatchers<
ReturnType<typeof expect.stringContaining>,
any
> {}
}