Skip to content

Commit df349e4

Browse files
authored
Merge branch 'main' into feat/advance-timers-wrapper
2 parents efd21b4 + ba8dfb8 commit df349e4

File tree

6 files changed

+22
-64
lines changed

6 files changed

+22
-64
lines changed

.all-contributorsrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,6 +1424,16 @@
14241424
"contributions": [
14251425
"code"
14261426
]
1427+
},
1428+
{
1429+
"login": "istateside",
1430+
"name": "Kevin Fleischman",
1431+
"avatar_url": "https://avatars.githubusercontent.com/u/7245931?v=4",
1432+
"profile": "http://www.hawkeye.dog",
1433+
"contributions": [
1434+
"code",
1435+
"test"
1436+
]
14271437
}
14281438
],
14291439
"repoHost": "https://github.com"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ Thanks goes to these people ([emoji key][emojis]):
317317
<td align="center"><a href="https://github.com/G-Rath"><img src="https://avatars.githubusercontent.com/u/3151613?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Gareth Jones</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=G-Rath" title="Code">💻</a> <a href="https://github.com/testing-library/dom-testing-library/commits?author=G-Rath" title="Tests">⚠️</a></td>
318318
<td align="center"><a href="https://github.com/riotrah"><img src="https://avatars.githubusercontent.com/u/22646419?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Rayat Rahman</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=riotrah" title="Code">💻</a></td>
319319
<td align="center"><a href="https://github.com/savcni01"><img src="https://avatars.githubusercontent.com/u/18025894?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Nik Savchenko</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=savcni01" title="Code">💻</a></td>
320+
<td align="center"><a href="http://www.hawkeye.dog"><img src="https://avatars.githubusercontent.com/u/7245931?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Kevin Fleischman</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=istateside" title="Code">💻</a> <a href="https://github.com/testing-library/dom-testing-library/commits?author=istateside" title="Tests">⚠️</a></td>
320321
</tr>
321322
</table>
322323

src/__tests__/element-queries.js

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

4-
beforeEach(() => {
5-
document.defaultView.Cypress = null
6-
})
7-
84
test('query can return null', () => {
95
const {
106
queryByLabelText,
@@ -1061,46 +1057,6 @@ test('the debug helper prints the dom state here', () => {
10611057
process.env.DEBUG_PRINT_LIMIT = originalDebugPrintLimit
10621058
})
10631059

1064-
test('get throws a useful error message without DOM in Cypress', () => {
1065-
document.defaultView.Cypress = {}
1066-
const {
1067-
getByLabelText,
1068-
getByPlaceholderText,
1069-
getByText,
1070-
getByTestId,
1071-
getByAltText,
1072-
getByTitle,
1073-
getByDisplayValue,
1074-
} = render('<div />')
1075-
expect(() =>
1076-
getByLabelText('LucyRicardo'),
1077-
).toThrowErrorMatchingInlineSnapshot(
1078-
`Unable to find a label with the text of: LucyRicardo`,
1079-
)
1080-
expect(() =>
1081-
getByPlaceholderText('LucyRicardo'),
1082-
).toThrowErrorMatchingInlineSnapshot(
1083-
`Unable to find an element with the placeholder text of: LucyRicardo`,
1084-
)
1085-
expect(() => getByText('LucyRicardo')).toThrowErrorMatchingInlineSnapshot(
1086-
`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.`,
1087-
)
1088-
expect(() => getByTestId('LucyRicardo')).toThrowErrorMatchingInlineSnapshot(
1089-
`Unable to find an element by: [data-testid="LucyRicardo"]`,
1090-
)
1091-
expect(() => getByAltText('LucyRicardo')).toThrowErrorMatchingInlineSnapshot(
1092-
`Unable to find an element with the alt text: LucyRicardo`,
1093-
)
1094-
expect(() => getByTitle('LucyRicardo')).toThrowErrorMatchingInlineSnapshot(
1095-
`Unable to find an element with the title: LucyRicardo.`,
1096-
)
1097-
expect(() =>
1098-
getByDisplayValue('LucyRicardo'),
1099-
).toThrowErrorMatchingInlineSnapshot(
1100-
`Unable to find an element with the display value: LucyRicardo.`,
1101-
)
1102-
})
1103-
11041060
test('getByText ignores script tags by default', () => {
11051061
const {getAllByText} = render(
11061062
'<script>Hello</script><div>Hello</div><style>.Hello{}</style>',

src/__tests__/pretty-dom.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ test('prettyDOM prints out the given DOM element tree', () => {
2626
test('prettyDOM supports truncating the output length', () => {
2727
const {container} = render('<div>Hello World!</div>')
2828
expect(prettyDOM(container, 5)).toMatch(/\.\.\./)
29+
expect(prettyDOM(container, 0)).toMatch('')
30+
expect(prettyDOM(container, Number.POSITIVE_INFINITY)).toMatchInlineSnapshot(`
31+
"<div>
32+
<div>
33+
Hello World!
34+
</div>
35+
</div>"
36+
`)
2937
})
3038

3139
test('prettyDOM defaults to document.body', () => {

src/config.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,7 @@ let config: InternalConfig = {
3636
const error = new Error(
3737
[
3838
message,
39-
prettifiedDOM.length > 0
40-
? `Ignored nodes: comments, <script />, <style />\n${prettyDOM(
41-
container,
42-
)}`
43-
: null,
39+
`Ignored nodes: comments, <script />, <style />\n${prettifiedDOM}`,
4440
]
4541
.filter(Boolean)
4642
.join('\n\n'),

src/pretty-dom.js

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,11 @@ import {getUserCodeFrame} from './get-user-code-frame'
44
import {getDocument} from './helpers'
55
import {DEFAULT_IGNORE_TAGS} from './shared'
66

7-
function inCypress(dom) {
8-
const window =
9-
(dom.ownerDocument && dom.ownerDocument.defaultView) || undefined
10-
return (
11-
(typeof global !== 'undefined' && global.Cypress) ||
12-
(typeof window !== 'undefined' && window.Cypress)
13-
)
14-
}
15-
167
const inNode = () =>
178
typeof process !== 'undefined' &&
189
process.versions !== undefined &&
1910
process.versions.node !== undefined
2011

21-
const getMaxLength = dom =>
22-
inCypress(dom)
23-
? 0
24-
: (typeof process !== 'undefined' && process.env.DEBUG_PRINT_LIMIT) || 7000
25-
2612
const {DOMCollection} = prettyFormat.plugins
2713

2814
// https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType#node_type_constants
@@ -43,7 +29,8 @@ function prettyDOM(dom, maxLength, options = {}) {
4329
dom = getDocument().body
4430
}
4531
if (typeof maxLength !== 'number') {
46-
maxLength = getMaxLength(dom)
32+
maxLength =
33+
(typeof process !== 'undefined' && process.env.DEBUG_PRINT_LIMIT) || 7000
4734
}
4835

4936
if (maxLength === 0) {

0 commit comments

Comments
 (0)