diff --git a/src/__node_tests__/index.js b/src/__node_tests__/index.js
index d1b08a12..0f88c323 100644
--- a/src/__node_tests__/index.js
+++ b/src/__node_tests__/index.js
@@ -96,3 +96,78 @@ test('byRole works without a global DOM', () => {
`)
})
+
+test('findBy works without a global DOM', async () => {
+ const {window} = new JSDOM(`
+
test text content
+
display value
+
+
+
+
+
+
+
+
`)
+
+ await expect(
+ dtl.findByLabelText(window.document, 'test-label'),
+ ).resolves.toBeTruthy()
+ await expect(
+ dtl.findAllByLabelText(window.document, 'test-label'),
+ ).resolves.toHaveLength(1)
+ await expect(
+ dtl.findByPlaceholderText(window.document, 'placeholder'),
+ ).resolves.toBeTruthy()
+ await expect(
+ dtl.findAllByPlaceholderText(window.document, 'placeholder'),
+ ).resolves.toHaveLength(1)
+ await expect(
+ dtl.findByText(window.document, 'test text content'),
+ ).resolves.toBeTruthy()
+ await expect(
+ dtl.findAllByText(window.document, 'test text content'),
+ ).resolves.toHaveLength(1)
+ await expect(
+ dtl.findByAltText(window.document, 'test alt text'),
+ ).resolves.toBeTruthy()
+ await expect(
+ dtl.findAllByAltText(window.document, 'test alt text'),
+ ).resolves.toHaveLength(1)
+ await expect(
+ dtl.findByTitle(window.document, 'test title'),
+ ).resolves.toBeTruthy()
+ await expect(
+ dtl.findAllByTitle(window.document, 'test title'),
+ ).resolves.toHaveLength(1)
+ await expect(
+ dtl.findByDisplayValue(window.document, 'display value'),
+ ).resolves.toBeTruthy()
+ await expect(
+ dtl.findAllByDisplayValue(window.document, 'display value'),
+ ).resolves.toHaveLength(1)
+ await expect(dtl.findByRole(window.document, 'dialog')).resolves.toBeTruthy()
+ await expect(
+ dtl.findAllByRole(window.document, 'dialog'),
+ ).resolves.toHaveLength(1)
+ await expect(dtl.findByRole(window.document, 'meter')).resolves.toBeTruthy()
+ await expect(
+ dtl.findAllByRole(window.document, 'meter'),
+ ).resolves.toHaveLength(1)
+ await expect(
+ dtl.findByRole(window.document, 'progressbar', {queryFallbacks: true}),
+ ).resolves.toBeTruthy()
+ await expect(
+ dtl.findAllByRole(window.document, 'progressbar', {queryFallbacks: true}),
+ ).resolves.toHaveLength(1)
+ await expect(dtl.findByRole(window.document, 'banner')).resolves.toBeTruthy()
+ await expect(
+ dtl.findAllByRole(window.document, 'banner'),
+ ).resolves.toHaveLength(1)
+ await expect(
+ dtl.findByTestId(window.document, 'test-id'),
+ ).resolves.toBeTruthy()
+ await expect(
+ dtl.findAllByTestId(window.document, 'test-id'),
+ ).resolves.toHaveLength(1)
+})
diff --git a/src/query-helpers.js b/src/query-helpers.js
index 48ff176d..dc7f02b8 100644
--- a/src/query-helpers.js
+++ b/src/query-helpers.js
@@ -90,10 +90,14 @@ function makeGetAllQuery(allQuery, getMissingError) {
// this accepts a getter query function and returns a function which calls
// waitFor and passing a function which invokes the getter.
function makeFindQuery(getter) {
- return (container, text, options, waitForOptions) =>
- waitFor(() => {
- return getter(container, text, options)
- }, waitForOptions)
+ return (container, text, options, waitForOptions) => {
+ return waitFor(
+ () => {
+ return getter(container, text, options)
+ },
+ {container, ...waitForOptions},
+ )
+ }
}
const wrapSingleQueryWithSuggestion = (query, queryAllByName, variant) => (
diff --git a/src/wait-for.js b/src/wait-for.js
index a1a49f5b..9eb44842 100644
--- a/src/wait-for.js
+++ b/src/wait-for.js
@@ -8,6 +8,7 @@ import {
setImmediate,
setTimeout,
clearTimeout,
+ checkContainerType,
} from './helpers'
import {getConfig, runWithExpensiveErrorDiagnosticsDisabled} from './config'
@@ -89,6 +90,12 @@ function waitFor(
await new Promise(r => setImmediate(r))
}
} else {
+ try {
+ checkContainerType(container)
+ } catch (e) {
+ reject(e)
+ return
+ }
intervalId = setInterval(checkRealTimersCallback, interval)
const {MutationObserver} = getWindowFromNode(container)
observer = new MutationObserver(checkRealTimersCallback)