Skip to content

Commit f27d14c

Browse files
bpintoeps1lon
andauthored
test: Fix inline snapshot mismatch on certain machines (#1040)
Co-authored-by: Sebastian Silbermann <[email protected]>
1 parent 8746d21 commit f27d14c

File tree

9 files changed

+410
-410
lines changed

9 files changed

+410
-410
lines changed

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"@testing-library/jest-dom": "^5.11.6",
5353
"@types/lz-string": "^1.3.34",
5454
"jest-in-case": "^1.0.2",
55-
"jest-serializer-ansi": "^1.0.3",
55+
"jest-snapshot-serializer-ansi": "^1.0.0",
5656
"jest-watch-select-projects": "^2.0.0",
5757
"jsdom": "^16.4.0",
5858
"kcd-scripts": "^11.0.0",

Diff for: src/__tests__/__snapshots__/role-helpers.js.snap

+2-2
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
`;

Diff for: src/__tests__/element-queries.js

+32-32
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
})

Diff for: src/__tests__/pretty-dom.js

+16-16
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,21 +28,21 @@ 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

3939
test('prettyDOM defaults to document.body', () => {
4040
const defaultInlineSnapshot = `
41-
"<body>
41+
<body>
4242
<div>
4343
Hello World!
4444
</div>
45-
</body>"
45+
</body>
4646
`
4747
renderIntoDocument('<div>Hello World!</div>')
4848
expect(prettyDOM()).toMatchInlineSnapshot(defaultInlineSnapshot)
@@ -51,10 +51,10 @@ test('prettyDOM defaults to document.body', () => {
5151

5252
test('prettyDOM supports receiving the document element', () => {
5353
expect(prettyDOM(document)).toMatchInlineSnapshot(`
54-
"<html>
54+
<html>
5555
<head />
5656
<body />
57-
</html>"
57+
</html>
5858
`)
5959
})
6060

@@ -63,11 +63,11 @@ test('logDOM logs prettyDOM to the console', () => {
6363
logDOM(container)
6464
expect(console.log).toHaveBeenCalledTimes(1)
6565
expect(console.log.mock.calls[0][0]).toMatchInlineSnapshot(`
66-
"<div>
66+
<div>
6767
<div>
6868
Hello World!
6969
</div>
70-
</div>"
70+
</div>
7171
`)
7272
})
7373

@@ -85,7 +85,7 @@ test('logDOM logs prettyDOM with code frame to the console', () => {
8585
logDOM(container)
8686
expect(console.log).toHaveBeenCalledTimes(1)
8787
expect(console.log.mock.calls[0][0]).toMatchInlineSnapshot(`
88-
"<div>
88+
<div>
8989
<div>
9090
Hello World!
9191
</div>
@@ -97,7 +97,7 @@ test('logDOM logs prettyDOM with code frame to the console', () => {
9797
> 7 | screen.debug()
9898
| ^
9999
"
100-
"
100+
101101
`)
102102
})
103103

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

127127
expect(prettyDOM(container)).toMatchInlineSnapshot(`
128-
"<body>
128+
<body>
129129
<p>
130130
Hello, Dave
131131
</p>
132-
</body>"
132+
</body>
133133
`)
134134
})
135135

@@ -141,14 +141,14 @@ test('prettyDOM can include all elements with a custom filter', () => {
141141
expect(
142142
prettyDOM(container, Number.POSITIVE_INFINITY, {filterNode: () => true}),
143143
).toMatchInlineSnapshot(`
144-
"<body>
144+
<body>
145145
<script
146146
src="context.js"
147147
/>
148148
<!-- Some comment -->
149149
<p>
150150
Hello, Dave
151151
</p>
152-
</body>"
152+
</body>
153153
`)
154154
})

0 commit comments

Comments
 (0)