Skip to content

Commit d971798

Browse files
authored
Merge branch 'main' into chore/ts/helpers
2 parents 0c44930 + d50a967 commit d971798

File tree

8 files changed

+126
-88
lines changed

8 files changed

+126
-88
lines changed

.all-contributorsrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,6 +1553,15 @@
15531553
"contributions": [
15541554
"code"
15551555
]
1556+
},
1557+
{
1558+
"login": "kalmi",
1559+
"name": "Tarnay Kálmán",
1560+
"avatar_url": "https://avatars.githubusercontent.com/u/54426?v=4",
1561+
"profile": "https://github.com/kalmi",
1562+
"contributions": [
1563+
"code"
1564+
]
15561565
}
15571566
],
15581567
"repoHost": "https://github.com"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ Thanks goes to these people ([emoji key][emojis]):
335335
<td align="center"><a href="https://www.robin-drexler.com/"><img src="https://avatars.githubusercontent.com/u/474248?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Robin Drexler</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=robin-drexler" title="Code">💻</a></td>
336336
<td align="center"><a href="https://github.com/dolevoper"><img src="https://avatars.githubusercontent.com/u/53278705?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Omer Dolev</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=dolevoper" title="Code">💻</a></td>
337337
<td align="center"><a href="https://github.com/Lirlev48"><img src="https://avatars.githubusercontent.com/u/58209233?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Lirlev48</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=Lirlev48" title="Code">💻</a></td>
338+
<td align="center"><a href="https://github.com/kalmi"><img src="https://avatars.githubusercontent.com/u/54426?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Tarnay Kálmán</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=kalmi" title="Code">💻</a></td>
338339
</tr>
339340
</table>
340341

src/__tests__/element-queries.js

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1-
import {configure} from '../config'
1+
import {configure, getConfig} from '../config'
22
import {render, renderIntoDocument} from './helpers/test-utils'
33

4+
// set original config
5+
let originalConfig
6+
beforeAll(() => {
7+
originalConfig = getConfig()
8+
})
9+
10+
afterEach(() => {
11+
configure(originalConfig)
12+
})
13+
414
test('query can return null', () => {
515
const {
616
queryByLabelText,
@@ -35,7 +45,7 @@ test('get throws a useful error message', () => {
3545
.toThrowErrorMatchingInlineSnapshot(`
3646
Unable to find a label with the text of: LucyRicardo
3747
38-
Ignored nodes: comments, <script />, <style />
48+
Ignored nodes: comments, script, style
3949
<div>
4050
<div />
4151
</div>
@@ -44,15 +54,15 @@ test('get throws a useful error message', () => {
4454
.toThrowErrorMatchingInlineSnapshot(`
4555
Unable to find an element with the placeholder text of: LucyRicardo
4656
47-
Ignored nodes: comments, <script />, <style />
57+
Ignored nodes: comments, script, style
4858
<div>
4959
<div />
5060
</div>
5161
`)
5262
expect(() => getByText('LucyRicardo')).toThrowErrorMatchingInlineSnapshot(`
5363
Unable to find an element with the text: LucyRicardo. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.
5464
55-
Ignored nodes: comments, <script />, <style />
65+
Ignored nodes: comments, script, style
5666
<div>
5767
<div />
5868
</div>
@@ -61,31 +71,31 @@ test('get throws a useful error message', () => {
6171
.toThrowErrorMatchingInlineSnapshot(`
6272
Unable to find an element with the text: Lucy Ricardo (normalized from 'Lucy Ricardo'). This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.
6373
64-
Ignored nodes: comments, <script />, <style />
74+
Ignored nodes: comments, script, style
6575
<div>
6676
<div />
6777
</div>
6878
`)
6979
expect(() => getByTestId('LucyRicardo')).toThrowErrorMatchingInlineSnapshot(`
7080
Unable to find an element by: [data-testid="LucyRicardo"]
7181
72-
Ignored nodes: comments, <script />, <style />
82+
Ignored nodes: comments, script, style
7383
<div>
7484
<div />
7585
</div>
7686
`)
7787
expect(() => getByAltText('LucyRicardo')).toThrowErrorMatchingInlineSnapshot(`
7888
Unable to find an element with the alt text: LucyRicardo
7989
80-
Ignored nodes: comments, <script />, <style />
90+
Ignored nodes: comments, script, style
8191
<div>
8292
<div />
8393
</div>
8494
`)
8595
expect(() => getByTitle('LucyRicardo')).toThrowErrorMatchingInlineSnapshot(`
8696
Unable to find an element with the title: LucyRicardo.
8797
88-
Ignored nodes: comments, <script />, <style />
98+
Ignored nodes: comments, script, style
8999
<div>
90100
<div />
91101
</div>
@@ -94,7 +104,7 @@ test('get throws a useful error message', () => {
94104
.toThrowErrorMatchingInlineSnapshot(`
95105
Unable to find an element with the display value: LucyRicardo.
96106
97-
Ignored nodes: comments, <script />, <style />
107+
Ignored nodes: comments, script, style
98108
<div>
99109
<div />
100110
</div>
@@ -104,7 +114,7 @@ test('get throws a useful error message', () => {
104114
105115
There are no accessible roles. But there might be some inaccessible roles. If you wish to access them, then set the \`hidden\` option to \`true\`. Learn more about this here: https://testing-library.com/docs/dom-testing-library/api-queries#byrole
106116
107-
Ignored nodes: comments, <script />, <style />
117+
Ignored nodes: comments, script, style
108118
<div>
109119
<div />
110120
</div>
@@ -371,7 +381,7 @@ test('label with no form control', () => {
371381
expect(() => getByLabelText(/alone/)).toThrowErrorMatchingInlineSnapshot(`
372382
Found a label with the text of: /alone/, however no form control was found associated to that label. Make sure you're using the "for" attribute or "aria-labelledby" attribute correctly.
373383
374-
Ignored nodes: comments, <script />, <style />
384+
Ignored nodes: comments, script, style
375385
<div>
376386
<label>
377387
All alone
@@ -389,7 +399,7 @@ test('label with "for" attribute but no form control and fuzzy matcher', () => {
389399
.toThrowErrorMatchingInlineSnapshot(`
390400
Found a label with the text of: alone, however no form control was found associated to that label. Make sure you're using the "for" attribute or "aria-labelledby" attribute correctly.
391401
392-
Ignored nodes: comments, <script />, <style />
402+
Ignored nodes: comments, script, style
393403
<div>
394404
<label
395405
for="foo"
@@ -412,7 +422,7 @@ test('label with children with no form control', () => {
412422
.toThrowErrorMatchingInlineSnapshot(`
413423
Found a label with the text of: /alone/, however no form control was found associated to that label. Make sure you're using the "for" attribute or "aria-labelledby" attribute correctly.
414424
415-
Ignored nodes: comments, <script />, <style />
425+
Ignored nodes: comments, script, style
416426
<div>
417427
418428
@@ -453,7 +463,7 @@ test('label with non-labellable element', () => {
453463
expect(() => getByLabelText(/Label/)).toThrowErrorMatchingInlineSnapshot(`
454464
Found a label with the text of: /Label/, however the element associated with this label (<div />) is non-labellable [https://html.spec.whatwg.org/multipage/forms.html#category-label]. If you really need to label a <div />, you can use aria-label or aria-labelledby instead.
455465
456-
Ignored nodes: comments, <script />, <style />
466+
Ignored nodes: comments, script, style
457467
<div>
458468
459469
@@ -503,7 +513,7 @@ test('multiple labels with non-labellable elements', () => {
503513
504514
Found a label with the text of: /Label/, however the element associated with this label (<p />) is non-labellable [https://html.spec.whatwg.org/multipage/forms.html#category-label]. If you really need to label a <p />, you can use aria-label or aria-labelledby instead.
505515
506-
Ignored nodes: comments, <script />, <style />
516+
Ignored nodes: comments, script, style
507517
<div>
508518
509519
@@ -555,7 +565,7 @@ test('totally empty label', () => {
555565
expect(() => getByLabelText('')).toThrowErrorMatchingInlineSnapshot(`
556566
Found a label with the text of: , however no form control was found associated to that label. Make sure you're using the "for" attribute or "aria-labelledby" attribute correctly.
557567
558-
Ignored nodes: comments, <script />, <style />
568+
Ignored nodes: comments, script, style
559569
<div>
560570
<label />
561571
</div>
@@ -1092,6 +1102,19 @@ test('the default value for `ignore` can be configured', () => {
10921102
expect(noStyle[1].tagName).toBe('DIV')
10931103
})
10941104

1105+
test('the default value for `ignore` is used in errors', () => {
1106+
configure({defaultIgnore: 'div'})
1107+
1108+
const {getByText} = render('<div>Hello</div>')
1109+
1110+
expect(() => getByText(/hello/i)).toThrowErrorMatchingInlineSnapshot(`
1111+
Unable to find an element with the text: /hello/i. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.
1112+
1113+
Ignored nodes: comments, div
1114+
<div />
1115+
`)
1116+
})
1117+
10951118
test('get/query input element by current value', () => {
10961119
const {getByDisplayValue, queryByDisplayValue, getByTestId} =
10971120
renderIntoDocument(`
@@ -1206,7 +1229,7 @@ test('return a proper error message when no label is found and there is an aria-
12061229
.toThrowErrorMatchingInlineSnapshot(`
12071230
Unable to find a label with the text of: LucyRicardo
12081231
1209-
Ignored nodes: comments, <script />, <style />
1232+
Ignored nodes: comments, script, style
12101233
<div>
12111234
<input
12121235
aria-labelledby="not-existing-label"
@@ -1276,7 +1299,7 @@ test('ByText error message ignores not the same elements as configured in `ignor
12761299
).toThrowErrorMatchingInlineSnapshot(`
12771300
Unable to find an element with the text: .css-selector. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.
12781301
1279-
Ignored nodes: comments, <script />, <style />
1302+
Ignored nodes: comments, script, style
12801303
<body>
12811304
12821305

0 commit comments

Comments
 (0)