You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
describe('window retrieval throws when given something other than a node',()=>{
8
+
test('Promise as node',()=>{
9
+
expect(()=>
10
+
getWindowFromNode(newPromise(jest.fn())),
11
+
).toThrowErrorMatchingInlineSnapshot(
12
+
`"It looks like you passed a Promise object instead of a DOM node. Did you do something like \`fireEvent.click(screen.findBy...\` when you meant to do \`fireEvent.click(await screen.getBy...\`?"`,
`"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"`,
18
+
)
19
+
})
20
+
})
21
+
7
22
describe('query container validation throws when validation fails',()=>{
Copy file name to clipboardExpand all lines: src/helpers.js
+5-2Lines changed: 5 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -47,7 +47,6 @@ function getDocument() {
47
47
returnwindow.document
48
48
}
49
49
functiongetWindowFromNode(node){
50
-
// istanbul ignore next I'm not sure what could cause the final else so we'll leave it uncovered.
51
50
if(node.defaultView){
52
51
// node is document
53
52
returnnode.defaultView
@@ -57,8 +56,12 @@ function getWindowFromNode(node) {
57
56
}elseif(node.window){
58
57
// node is window
59
58
returnnode.window
59
+
}elseif(node.theninstanceofFunction){
60
+
thrownewError(
61
+
`It looks like you passed a Promise object instead of a DOM node. Did you do something like \`fireEvent.click(screen.findBy...\` when you meant to do \`fireEvent.click(await screen.getBy...\`?`,
62
+
)
60
63
}else{
61
-
// no idea...
64
+
// The user passed something unusual to a calling function
62
65
thrownewError(
63
66
`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`,
0 commit comments