Skip to content

Commit

Permalink
Merge branch 'main' into feat/fix-queries-with-nbsp-in-dom
Browse files Browse the repository at this point in the history
  • Loading branch information
savcni01 authored May 11, 2021
2 parents ee1bd91 + c273ed5 commit 36faca6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/__tests__/helpers.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {screen} from '../'
import {
getDocument,
getWindowFromNode,
Expand All @@ -10,6 +11,13 @@ test('returns global document if exists', () => {
})

describe('window retrieval throws when given something other than a node', () => {
// we had an issue when user insert screen instead of query
// actually here should be another more clear error output
test('screen as node', () => {
expect(() => getWindowFromNode(screen)).toThrowErrorMatchingInlineSnapshot(
`"It looks like you passed a \`screen\` object. Did you do something like \`fireEvent.click(screen, ...\` when you meant to use a query, e.g. \`fireEvent.click(screen.getBy..., \`?"`,
)
})
test('Promise as node', () => {
expect(() =>
getWindowFromNode(new Promise(jest.fn())),
Expand Down
7 changes: 7 additions & 0 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ function getWindowFromNode(node) {
throw new Error(
`It looks like you passed an Array instead of a DOM node. Did you do something like \`fireEvent.click(screen.getAllBy...\` when you meant to use a \`getBy\` query \`fireEvent.click(screen.getBy...\`?`,
)
} else if (
typeof node.debug === 'function' &&
typeof node.logTestingPlaygroundURL === 'function'
) {
throw new Error(
`It looks like you passed a \`screen\` object. Did you do something like \`fireEvent.click(screen, ...\` when you meant to use a query, e.g. \`fireEvent.click(screen.getBy..., \`?`,
)
} else {
// The user passed something unusual to a calling function
throw new Error(
Expand Down

0 comments on commit 36faca6

Please sign in to comment.