diff --git a/src/__tests__/element-queries.js b/src/__tests__/element-queries.js index d49d62c8..6f1a1f92 100644 --- a/src/__tests__/element-queries.js +++ b/src/__tests__/element-queries.js @@ -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(() => { @@ -486,19 +486,19 @@ test('test the debug helper prints the dom state here', () => { })} ` - 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 = `
Hello World!
` - 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(/^((?!\.\.\.).)*$/), diff --git a/src/__tests__/helpers/test-utils.js b/src/__tests__/helpers/test-utils.js index 46d270d9..9a31e232 100644 --- a/src/__tests__/helpers/test-utils.js +++ b/src/__tests__/helpers/test-utils.js @@ -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} diff --git a/src/query-helpers.js b/src/query-helpers.js index 3f3e7e56..20adc0c4 100644 --- a/src/query-helpers.js +++ b/src/query-helpers.js @@ -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) {