Skip to content

Commit 52adb24

Browse files
committed
Merge branch 'features/drop-support-for-node-14' of github.com:MatanBobi/dom-testing-library into features/drop-support-for-node-14
2 parents d2b086a + 5ec7c12 commit 52adb24

File tree

11 files changed

+352
-33
lines changed

11 files changed

+352
-33
lines changed

.all-contributorsrc

+20-1
Original file line numberDiff line numberDiff line change
@@ -1598,8 +1598,27 @@
15981598
"contributions": [
15991599
"code"
16001600
]
1601+
},
1602+
{
1603+
"login": "jlp-craigmorten",
1604+
"name": "Craig Morten",
1605+
"avatar_url": "https://avatars.githubusercontent.com/u/124147726?v=4",
1606+
"profile": "https://github.com/jlp-craigmorten",
1607+
"contributions": [
1608+
"code"
1609+
]
1610+
},
1611+
{
1612+
"login": "naorpeled",
1613+
"name": "Naor Peled",
1614+
"avatar_url": "https://avatars.githubusercontent.com/u/6171622?v=4",
1615+
"profile": "https://naor.dev",
1616+
"contributions": [
1617+
"code"
1618+
]
16011619
}
16021620
],
16031621
"repoHost": "https://github.com",
1604-
"commitConvention": "angular"
1622+
"commitConvention": "angular",
1623+
"commitType": "docs"
16051624
}

.github/workflows/validate.yml

+5-9
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@ on:
1111
- 'beta'
1212
- 'alpha'
1313
- '!all-contributors/**'
14-
pull_request: {}
14+
pull_request:
15+
16+
concurrency:
17+
group: ${{ github.workflow }}-${{ github.ref }}
18+
cancel-in-progress: true
1519

1620
permissions: {}
1721

1822
jobs:
1923
main:
2024
permissions:
21-
actions: write # to cancel/stop running workflows (styfle/cancel-workflow-action)
2225
contents: read # to fetch code (actions/checkout)
2326
# ignore all-contributors PRs
2427
if: ${{ !contains(github.head_ref, 'all-contributors') }}
@@ -29,9 +32,6 @@ jobs:
2932
node: [16, 18, 20]
3033
runs-on: ubuntu-latest
3134
steps:
32-
- name: 🛑 Cancel Previous Runs
33-
uses: styfle/[email protected]
34-
3535
- name: ⬇️ Checkout repo
3636
uses: actions/checkout@v3
3737
with:
@@ -63,7 +63,6 @@ jobs:
6363

6464
release:
6565
permissions:
66-
actions: write # to cancel/stop running workflows (styfle/cancel-workflow-action)
6766
contents: write # to create release tags (cycjimmy/semantic-release-action)
6867
issues: write # to post release that resolves an issue
6968

@@ -73,9 +72,6 @@ jobs:
7372
${{ github.repository == 'testing-library/dom-testing-library' &&
7473
github.event_name == 'push' }}
7574
steps:
76-
- name: 🛑 Cancel Previous Runs
77-
uses: styfle/[email protected]
78-
7975
- name: ⬇️ Checkout repo
8076
uses: actions/checkout@v3
8177

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,8 @@ Thanks goes to these people ([emoji key][emojis]):
343343
<td align="center" valign="top" width="14.28%"><a href="https://github.com/raplemie"><img src="https://avatars.githubusercontent.com/u/1904889?v=4?s=100" width="100px;" alt="Raphaël LEMIEUX"/><br /><sub><b>Raphaël LEMIEUX</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=raplemie" title="Code">💻</a></td>
344344
<td align="center" valign="top" width="14.28%"><a href="https://github.com/arthurlvilasboas"><img src="https://avatars.githubusercontent.com/u/95368212?v=4?s=100" width="100px;" alt="Arthur Lauck Vilas Boas"/><br /><sub><b>Arthur Lauck Vilas Boas</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=arthurlvilasboas" title="Documentation">📖</a></td>
345345
<td align="center" valign="top" width="14.28%"><a href="https://github.com/DaniAcu"><img src="https://avatars.githubusercontent.com/u/26409015?v=4?s=100" width="100px;" alt="Daniel Acuña"/><br /><sub><b>Daniel Acuña</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=DaniAcu" title="Code">💻</a></td>
346+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/jlp-craigmorten"><img src="https://avatars.githubusercontent.com/u/124147726?v=4?s=100" width="100px;" alt="Craig Morten"/><br /><sub><b>Craig Morten</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=jlp-craigmorten" title="Code">💻</a></td>
347+
<td align="center" valign="top" width="14.28%"><a href="https://naor.dev"><img src="https://avatars.githubusercontent.com/u/6171622?v=4?s=100" width="100px;" alt="Naor Peled"/><br /><sub><b>Naor Peled</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=naorpeled" title="Code">💻</a></td>
346348
</tr>
347349
</tbody>
348350
</table>

package.json

+8-3
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,27 @@
6262
"@babel/code-frame": "^7.10.4",
6363
"@babel/runtime": "^7.12.5",
6464
"@types/aria-query": "^5.0.1",
65-
"aria-query": "^5.0.0",
65+
"aria-query": "5.1.3",
6666
"chalk": "^4.1.0",
6767
"dom-accessibility-api": "^0.5.9",
68-
"lz-string": "^1.4.4",
68+
"lz-string": "^1.5.0",
6969
"pretty-format": "^27.0.2"
7070
},
7171
"devDependencies": {
7272
"@testing-library/jest-dom": "^5.11.6",
73-
"@types/lz-string": "^1.3.34",
73+
"browserslist": "4.21.8",
74+
"caniuse-lite": "1.0.30001502",
7475
"jest-in-case": "^1.0.2",
7576
"jest-snapshot-serializer-ansi": "^1.0.0",
7677
"jest-watch-select-projects": "^2.0.0",
7778
"jsdom": "20.0.0",
7879
"kcd-scripts": "^13.0.0",
7980
"typescript": "^4.1.2"
8081
},
82+
"overrides": {
83+
"browserslist": "4.21.8",
84+
"caniuse-lite": "1.0.30001502"
85+
},
8186
"eslintConfig": {
8287
"extends": [
8388
"./node_modules/kcd-scripts/eslint.js",

src/__tests__/ariaAttributes.js

+121
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,28 @@ test('`expanded` throws on unsupported roles', () => {
3636
)
3737
})
3838

39+
test('`busy` throws on unsupported roles', () => {
40+
const {getByRole} = render(
41+
`<div aria-busy="true" role="none">Hello, Dave!</div>`,
42+
)
43+
expect(() =>
44+
getByRole('none', {busy: true}),
45+
).toThrowErrorMatchingInlineSnapshot(
46+
`"aria-busy" is not supported on role "none".`,
47+
)
48+
})
49+
50+
test('`busy: true|false` matches `busy` regions', () => {
51+
const {getByRole} = renderIntoDocument(
52+
`<div>
53+
<div role="log" aria-busy="true" />
54+
<div role="log" aria-busy="false" />
55+
</div>`,
56+
)
57+
expect(getByRole('log', {busy: true})).toBeInTheDocument()
58+
expect(getByRole('log', {busy: false})).toBeInTheDocument()
59+
})
60+
3961
test('`checked: true|false` matches `checked` checkboxes', () => {
4062
const {getByRole} = renderIntoDocument(
4163
`<div>
@@ -237,6 +259,105 @@ test('`level` throws on unsupported roles', () => {
237259
)
238260
})
239261

262+
test('`value.now` throws on unsupported roles', () => {
263+
const {getByRole} = render(`<button aria-valuenow="1">Button</button>`)
264+
expect(() =>
265+
getByRole('button', {value: {now: 1}}),
266+
).toThrowErrorMatchingInlineSnapshot(
267+
`"aria-valuenow" is not supported on role "button".`,
268+
)
269+
})
270+
271+
test('`value.now: number` matches `aria-valuenow` on widgets', () => {
272+
const {getByRole} = renderIntoDocument(
273+
`<div>
274+
<button role="spinbutton" />
275+
<button role="spinbutton" aria-valuenow="5" />
276+
<button role="spinbutton" aria-valuenow="10" />
277+
</div>`,
278+
)
279+
expect(getByRole('spinbutton', {value: {now: 5}})).toBeInTheDocument()
280+
expect(getByRole('spinbutton', {value: {now: 10}})).toBeInTheDocument()
281+
})
282+
283+
test('`value.max` throws on unsupported roles', () => {
284+
const {getByRole} = render(`<button aria-valuemax="1">Button</button>`)
285+
expect(() =>
286+
getByRole('button', {value: {max: 1}}),
287+
).toThrowErrorMatchingInlineSnapshot(
288+
`"aria-valuemax" is not supported on role "button".`,
289+
)
290+
})
291+
292+
test('`value.max: number` matches `aria-valuemax` on widgets', () => {
293+
const {getByRole} = renderIntoDocument(
294+
`<div>
295+
<button role="spinbutton" />
296+
<button role="spinbutton" aria-valuemax="5" />
297+
<button role="spinbutton" aria-valuemax="10" />
298+
</div>`,
299+
)
300+
expect(getByRole('spinbutton', {value: {max: 5}})).toBeInTheDocument()
301+
expect(getByRole('spinbutton', {value: {max: 10}})).toBeInTheDocument()
302+
})
303+
304+
test('`value.min` throws on unsupported roles', () => {
305+
const {getByRole} = render(`<button aria-valuemin="1">Button</button>`)
306+
expect(() =>
307+
getByRole('button', {value: {min: 1}}),
308+
).toThrowErrorMatchingInlineSnapshot(
309+
`"aria-valuemin" is not supported on role "button".`,
310+
)
311+
})
312+
313+
test('`value.min: number` matches `aria-valuemin` on widgets', () => {
314+
const {getByRole} = renderIntoDocument(
315+
`<div>
316+
<button role="spinbutton" />
317+
<button role="spinbutton" aria-valuemin="5" />
318+
<button role="spinbutton" aria-valuemin="10" />
319+
</div>`,
320+
)
321+
expect(getByRole('spinbutton', {value: {min: 5}})).toBeInTheDocument()
322+
expect(getByRole('spinbutton', {value: {min: 10}})).toBeInTheDocument()
323+
})
324+
325+
test('`value.text` throws on unsupported roles', () => {
326+
const {getByRole} = render(`<button aria-valuetext="one">Button</button>`)
327+
expect(() =>
328+
getByRole('button', {value: {text: 'one'}}),
329+
).toThrowErrorMatchingInlineSnapshot(
330+
`"aria-valuetext" is not supported on role "button".`,
331+
)
332+
})
333+
334+
test('`value.text: Matcher` matches `aria-valuetext` on widgets', () => {
335+
const {getAllByRole, getByRole} = renderIntoDocument(
336+
`<div>
337+
<button role="spinbutton" />
338+
<button role="spinbutton" aria-valuetext="zero" />
339+
<button role="spinbutton" aria-valuetext="few" />
340+
<button role="spinbutton" aria-valuetext="many" />
341+
</div>`,
342+
)
343+
expect(getByRole('spinbutton', {value: {text: 'zero'}})).toBeInTheDocument()
344+
expect(getAllByRole('spinbutton', {value: {text: /few|many/}})).toHaveLength(
345+
2,
346+
)
347+
})
348+
349+
test('`value.*` must all match if specified', () => {
350+
const {getByRole} = renderIntoDocument(
351+
`<div>
352+
<button role="spinbutton" aria-valuemin="0" aria-valuenow="1" aria-valuemax="10" aria-valuetext="eins" />
353+
<button role="spinbutton" aria-valuemin="0" aria-valuenow="1" aria-valuemax="10" aria-valuetext="one" />
354+
</div>`,
355+
)
356+
expect(
357+
getByRole('spinbutton', {value: {now: 1, text: 'one'}}),
358+
).toBeInTheDocument()
359+
})
360+
240361
test('`expanded: true|false` matches `expanded` buttons', () => {
241362
const {getByRole} = renderIntoDocument(
242363
`<div>

src/__tests__/suggestions.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,15 @@ beforeAll(() => {
66
configure({throwSuggestions: true})
77
})
88

9+
beforeEach(() => {
10+
// We're testing suggestions of find* queries but we're not interested in their time-related behavior.
11+
// Real timers would make the test suite slower for no reason.
12+
jest.useFakeTimers()
13+
})
14+
915
afterEach(() => {
10-
configure({testIdAttribute: 'data-testid'})
16+
jest.useRealTimers()
17+
configure({testIdAttribute: 'data-testid', throwSuggestions: true})
1118
console.warn.mockClear()
1219
})
1320

@@ -103,6 +110,17 @@ test('should not suggest when suggest is turned off for a query', () => {
103110
).not.toThrowError()
104111
})
105112

113+
test('should suggest when suggest is turned on for a specific query but disabled in config', () => {
114+
configure({throwSuggestions: false})
115+
renderIntoDocument(`
116+
<button data-testid="foo">submit</button>
117+
<button data-testid="foot">another</button>`)
118+
119+
expect(() => screen.getByTestId('foo', {suggest: true})).toThrowError(
120+
"try this:\ngetByRole('button', { name: /submit/i })",
121+
)
122+
})
123+
106124
test('should suggest getByRole when used with getBy', () => {
107125
renderIntoDocument(`<button data-testid="foo">submit</button>`)
108126

0 commit comments

Comments
 (0)