Skip to content

Commit 90f331f

Browse files
committed
Restore prettyDOM logging for Cypress
1 parent ff84a50 commit 90f331f

File tree

2 files changed

+2
-59
lines changed

2 files changed

+2
-59
lines changed

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/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)