Skip to content

Commit 8debfaf

Browse files
committed
Update snapshot tests
1 parent 5710061 commit 8debfaf

File tree

7 files changed

+425
-407
lines changed

7 files changed

+425
-407
lines changed

src/__tests__/__snapshots__/role-helpers.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`logRoles calls console.log with output from prettyRoles 1`] = `
4-
"region:
4+
region:
55
66
Name "a region":
77
<section
@@ -200,5 +200,5 @@ Name "":
200200
data-testid="a-textarea"
201201
/>
202202
203-
--------------------------------------------------"
203+
--------------------------------------------------
204204
`;

src/__tests__/element-queries.js

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -33,72 +33,72 @@ test('get throws a useful error message', () => {
3333
)
3434
expect(() => getByLabelText('LucyRicardo'))
3535
.toThrowErrorMatchingInlineSnapshot(`
36-
"Unable to find a label with the text of: LucyRicardo
36+
Unable to find a label with the text of: LucyRicardo
3737
3838
Ignored nodes: comments, <script />, <style />
3939
<div>
4040
<div />
41-
</div>"
41+
</div>
4242
`)
4343
expect(() => getByPlaceholderText('LucyRicardo'))
4444
.toThrowErrorMatchingInlineSnapshot(`
45-
"Unable to find an element with the placeholder text of: LucyRicardo
45+
Unable to find an element with the placeholder text of: LucyRicardo
4646
4747
Ignored nodes: comments, <script />, <style />
4848
<div>
4949
<div />
50-
</div>"
50+
</div>
5151
`)
5252
expect(() => getByText('LucyRicardo')).toThrowErrorMatchingInlineSnapshot(`
53-
"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.
53+
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.
5454
5555
Ignored nodes: comments, <script />, <style />
5656
<div>
5757
<div />
58-
</div>"
58+
</div>
5959
`)
6060
expect(() => getByTestId('LucyRicardo')).toThrowErrorMatchingInlineSnapshot(`
61-
"Unable to find an element by: [data-testid="LucyRicardo"]
61+
Unable to find an element by: [data-testid="LucyRicardo"]
6262
6363
Ignored nodes: comments, <script />, <style />
6464
<div>
6565
<div />
66-
</div>"
66+
</div>
6767
`)
6868
expect(() => getByAltText('LucyRicardo')).toThrowErrorMatchingInlineSnapshot(`
69-
"Unable to find an element with the alt text: LucyRicardo
69+
Unable to find an element with the alt text: LucyRicardo
7070
7171
Ignored nodes: comments, <script />, <style />
7272
<div>
7373
<div />
74-
</div>"
74+
</div>
7575
`)
7676
expect(() => getByTitle('LucyRicardo')).toThrowErrorMatchingInlineSnapshot(`
77-
"Unable to find an element with the title: LucyRicardo.
77+
Unable to find an element with the title: LucyRicardo.
7878
7979
Ignored nodes: comments, <script />, <style />
8080
<div>
8181
<div />
82-
</div>"
82+
</div>
8383
`)
8484
expect(() => getByDisplayValue('LucyRicardo'))
8585
.toThrowErrorMatchingInlineSnapshot(`
86-
"Unable to find an element with the display value: LucyRicardo.
86+
Unable to find an element with the display value: LucyRicardo.
8787
8888
Ignored nodes: comments, <script />, <style />
8989
<div>
9090
<div />
91-
</div>"
91+
</div>
9292
`)
9393
expect(() => getByRole('LucyRicardo')).toThrowErrorMatchingInlineSnapshot(`
94-
"Unable to find an accessible element with the role "LucyRicardo"
94+
Unable to find an accessible element with the role "LucyRicardo"
9595
9696
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
9797
9898
Ignored nodes: comments, <script />, <style />
9999
<div>
100100
<div />
101-
</div>"
101+
</div>
102102
`)
103103
})
104104

@@ -360,14 +360,14 @@ test('label with no form control', () => {
360360
const {getByLabelText, queryByLabelText} = render(`<label>All alone</label>`)
361361
expect(queryByLabelText(/alone/)).toBeNull()
362362
expect(() => getByLabelText(/alone/)).toThrowErrorMatchingInlineSnapshot(`
363-
"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.
363+
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.
364364
365365
Ignored nodes: comments, <script />, <style />
366366
<div>
367367
<label>
368368
All alone
369369
</label>
370-
</div>"
370+
</div>
371371
`)
372372
})
373373

@@ -378,7 +378,7 @@ test('label with "for" attribute but no form control and fuzzy matcher', () => {
378378
expect(queryByLabelText('alone', {exact: false})).toBeNull()
379379
expect(() => getByLabelText('alone', {exact: false}))
380380
.toThrowErrorMatchingInlineSnapshot(`
381-
"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.
381+
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.
382382
383383
Ignored nodes: comments, <script />, <style />
384384
<div>
@@ -387,7 +387,7 @@ test('label with "for" attribute but no form control and fuzzy matcher', () => {
387387
>
388388
All alone label
389389
</label>
390-
</div>"
390+
</div>
391391
`)
392392
})
393393

@@ -401,7 +401,7 @@ test('label with children with no form control', () => {
401401
expect(queryByLabelText(/alone/, {selector: 'input'})).toBeNull()
402402
expect(() => getByLabelText(/alone/, {selector: 'input'}))
403403
.toThrowErrorMatchingInlineSnapshot(`
404-
"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.
404+
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.
405405
406406
Ignored nodes: comments, <script />, <style />
407407
<div>
@@ -426,7 +426,7 @@ test('label with children with no form control', () => {
426426
427427
428428
</label>
429-
</div>"
429+
</div>
430430
`)
431431
})
432432

@@ -442,7 +442,7 @@ test('label with non-labellable element', () => {
442442

443443
expect(queryByLabelText(/Label/)).toBeNull()
444444
expect(() => getByLabelText(/Label/)).toThrowErrorMatchingInlineSnapshot(`
445-
"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.
445+
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.
446446
447447
Ignored nodes: comments, <script />, <style />
448448
<div>
@@ -470,7 +470,7 @@ test('label with non-labellable element', () => {
470470
</div>
471471
472472
473-
</div>"
473+
</div>
474474
`)
475475
})
476476

@@ -490,7 +490,7 @@ test('multiple labels with non-labellable elements', () => {
490490

491491
expect(queryAllByLabelText(/Label/)).toEqual([])
492492
expect(() => getAllByLabelText(/Label/)).toThrowErrorMatchingInlineSnapshot(`
493-
"Found a label with the text of: /Label/, however the element associated with this label (<span />) is non-labellable [https://html.spec.whatwg.org/multipage/forms.html#category-label]. If you really need to label a <span />, you can use aria-label or aria-labelledby instead.
493+
Found a label with the text of: /Label/, however the element associated with this label (<span />) is non-labellable [https://html.spec.whatwg.org/multipage/forms.html#category-label]. If you really need to label a <span />, you can use aria-label or aria-labelledby instead.
494494
495495
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.
496496
@@ -536,20 +536,20 @@ test('multiple labels with non-labellable elements', () => {
536536
</div>
537537
538538
539-
</div>"
539+
</div>
540540
`)
541541
})
542542

543543
test('totally empty label', () => {
544544
const {getByLabelText, queryByLabelText} = render(`<label />`)
545545
expect(queryByLabelText('')).toBeNull()
546546
expect(() => getByLabelText('')).toThrowErrorMatchingInlineSnapshot(`
547-
"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.
547+
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.
548548
549549
Ignored nodes: comments, <script />, <style />
550550
<div>
551551
<label />
552-
</div>"
552+
</div>
553553
`)
554554
})
555555

@@ -1183,14 +1183,14 @@ test('return a proper error message when no label is found and there is an aria-
11831183

11841184
expect(() => getByLabelText('LucyRicardo'))
11851185
.toThrowErrorMatchingInlineSnapshot(`
1186-
"Unable to find a label with the text of: LucyRicardo
1186+
Unable to find a label with the text of: LucyRicardo
11871187
11881188
Ignored nodes: comments, <script />, <style />
11891189
<div>
11901190
<input
11911191
aria-labelledby="not-existing-label"
11921192
/>
1193-
</div>"
1193+
</div>
11941194
`)
11951195
})
11961196

@@ -1253,7 +1253,7 @@ test('ByText error message ignores not the same elements as configured in `ignor
12531253
expect(() =>
12541254
getByText('.css-selector', {selector: 'style', ignore: 'script'}),
12551255
).toThrowErrorMatchingInlineSnapshot(`
1256-
"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.
1256+
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.
12571257
12581258
Ignored nodes: comments, <script />, <style />
12591259
<body>
@@ -1266,6 +1266,6 @@ test('ByText error message ignores not the same elements as configured in `ignor
12661266
/>
12671267
12681268
1269-
</body>"
1269+
</body>
12701270
`)
12711271
})

src/__tests__/pretty-dom.js

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ afterEach(() => {
1515
test('prettyDOM prints out the given DOM element tree', () => {
1616
const {container} = render('<div>Hello World!</div>')
1717
expect(prettyDOM(container)).toMatchInlineSnapshot(`
18-
"<div>
18+
<div>
1919
<div>
2020
Hello World!
2121
</div>
22-
</div>"
22+
</div>
2323
`)
2424
})
2525

@@ -28,11 +28,11 @@ test('prettyDOM supports truncating the output length', () => {
2828
expect(prettyDOM(container, 5)).toMatch(/\.\.\./)
2929
expect(prettyDOM(container, 0)).toMatch('')
3030
expect(prettyDOM(container, Number.POSITIVE_INFINITY)).toMatchInlineSnapshot(`
31-
"<div>
31+
<div>
3232
<div>
3333
Hello World!
3434
</div>
35-
</div>"
35+
</div>
3636
`)
3737
})
3838

@@ -45,16 +45,34 @@ test('prettyDOM defaults to document.body', () => {
4545
</body>"
4646
`
4747
renderIntoDocument('<div>Hello World!</div>')
48-
expect(prettyDOM()).toMatchInlineSnapshot(defaultInlineSnapshot)
49-
expect(prettyDOM(null)).toMatchInlineSnapshot(defaultInlineSnapshot)
48+
expect(prettyDOM()).toMatchInlineSnapshot(
49+
defaultInlineSnapshot,
50+
`
51+
<body>
52+
<div>
53+
Hello World!
54+
</div>
55+
</body>
56+
`,
57+
)
58+
expect(prettyDOM(null)).toMatchInlineSnapshot(
59+
defaultInlineSnapshot,
60+
`
61+
<body>
62+
<div>
63+
Hello World!
64+
</div>
65+
</body>
66+
`,
67+
)
5068
})
5169

5270
test('prettyDOM supports receiving the document element', () => {
5371
expect(prettyDOM(document)).toMatchInlineSnapshot(`
54-
"<html>
72+
<html>
5573
<head />
5674
<body />
57-
</html>"
75+
</html>
5876
`)
5977
})
6078

@@ -63,11 +81,11 @@ test('logDOM logs prettyDOM to the console', () => {
6381
logDOM(container)
6482
expect(console.log).toHaveBeenCalledTimes(1)
6583
expect(console.log.mock.calls[0][0]).toMatchInlineSnapshot(`
66-
"<div>
84+
<div>
6785
<div>
6886
Hello World!
6987
</div>
70-
</div>"
88+
</div>
7189
`)
7290
})
7391

@@ -85,7 +103,7 @@ test('logDOM logs prettyDOM with code frame to the console', () => {
85103
logDOM(container)
86104
expect(console.log).toHaveBeenCalledTimes(1)
87105
expect(console.log.mock.calls[0][0]).toMatchInlineSnapshot(`
88-
"<div>
106+
<div>
89107
<div>
90108
Hello World!
91109
</div>
@@ -97,7 +115,7 @@ test('logDOM logs prettyDOM with code frame to the console', () => {
97115
> 7 | screen.debug()
98116
| ^
99117
"
100-
"
118+
101119
`)
102120
})
103121

@@ -125,11 +143,11 @@ test('prettyDOM ignores script elements and comments nodes by default', () => {
125143
)
126144

127145
expect(prettyDOM(container)).toMatchInlineSnapshot(`
128-
"<body>
146+
<body>
129147
<p>
130148
Hello, Dave
131149
</p>
132-
</body>"
150+
</body>
133151
`)
134152
})
135153

@@ -141,14 +159,14 @@ test('prettyDOM can include all elements with a custom filter', () => {
141159
expect(
142160
prettyDOM(container, Number.POSITIVE_INFINITY, {filterNode: () => true}),
143161
).toMatchInlineSnapshot(`
144-
"<body>
162+
<body>
145163
<script
146164
src="context.js"
147165
/>
148166
<!-- Some comment -->
149167
<p>
150168
Hello, Dave
151169
</p>
152-
</body>"
170+
</body>
153171
`)
154172
})

0 commit comments

Comments
 (0)