Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/__tests__/element-queries.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'jest-dom/extend-expect'
import {render} from './helpers/test-utils'
import {render, renderIntoDocument} from './helpers/test-utils'
import document from './helpers/document'

beforeEach(() => {
Expand Down Expand Up @@ -486,19 +486,19 @@ test('test the debug helper prints the dom state here', () => {
})}
</div>`

const {getByText} = render(Large) // render large DOM which exceeds 7000 limit
const {getByText} = renderIntoDocument(Large) // render large DOM which exceeds 7000 limit
expect(() => expect(getByText('not present')).toBeTruthy()).toThrowError()

const Hello = `<div data-testid="debugging" data-otherid="debugging">
Hello World!
</div>`
const {getByTestId} = render(Hello)
const {getByTestId} = renderIntoDocument(Hello)
process.env.DEBUG_PRINT_LIMIT = 5 // user should see `...`
expect(() => expect(getByTestId('not present')).toBeTruthy()).toThrowError(
/\.\.\./,
/\.\.\.$/,
)

const {getByLabelText} = render(Hello)
const {getByLabelText} = renderIntoDocument(Hello)
process.env.DEBUG_PRINT_LIMIT = 10000 // user shouldn't see `...`
expect(() =>
expect(getByLabelText('not present')).toBeTruthy(/^((?!\.\.\.).)*$/),
Expand Down
8 changes: 7 additions & 1 deletion src/__tests__/helpers/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@ function render(html) {
return {container, ...containerQueries}
}

export {render}
function renderIntoDocument(html) {
document.body.innerHTML = html
const containerQueries = getQueriesForElement(document)
return {container: document, ...containerQueries}
}

export {render, renderIntoDocument}
4 changes: 3 additions & 1 deletion src/query-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ function debugDOM(htmlElement) {
typeof process !== 'undefined' &&
process.versions !== undefined &&
process.versions.node !== undefined
const window = htmlElement.ownerDocument.defaultView
const window =
(htmlElement.ownerDocument && htmlElement.ownerDocument.defaultView) ||
undefined
const inCypress = typeof window !== 'undefined' && window.Cypress
/* istanbul ignore else */
if (inCypress) {
Expand Down