Skip to content

Commit 440a846

Browse files
committed
add test for HTMLElement with no window
1 parent bded1db commit 440a846

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/__tests__/helpers.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@ describe('window retrieval throws when given something other than a node', () =>
2525
`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...\`?`,
2626
)
2727
})
28+
test('HTMLElement as node', () => {
29+
const elem = document.createElement('div')
30+
Object.defineProperty(elem, 'ownerDocument', {
31+
get: function get() {
32+
return null
33+
},
34+
})
35+
36+
expect(() => getWindowFromNode(elem)).toThrowErrorMatchingInlineSnapshot(
37+
`Unable to find the "window" object for the given node. Please file an issue with the code that's causing you to see this error: https://github.com/testing-library/dom-testing-library/issues/new`,
38+
)
39+
})
40+
2841
test('unknown as node', () => {
2942
expect(() => getWindowFromNode({})).toThrowErrorMatchingInlineSnapshot(
3043
`The given node is not an HTMLElement, the node type is: object`,

0 commit comments

Comments
 (0)