Skip to content
This repository was archived by the owner on Aug 21, 2023. It is now read-only.

Commit 805aa00

Browse files
author
ItsJonQ
committed
Add tests
1 parent 2ca176f commit 805aa00

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import {
2+
getClosestDocument
3+
} from '../../node'
4+
5+
afterEach(() => {
6+
global.document.innerHTML = ''
7+
})
8+
9+
test('Returns global document, by default', () => {
10+
expect(getClosestDocument() === document).toBeTruthy()
11+
})
12+
13+
test('Returns global document, if argument is not a node', () => {
14+
expect(getClosestDocument('div') === document).toBeTruthy()
15+
})
16+
17+
test('Returns global document, node parent is global document', () => {
18+
const o = document.createElement('div')
19+
document.body.appendChild(o)
20+
21+
expect(getClosestDocument(o) === document).toBeTruthy()
22+
})
23+
24+
test('Returns closest document of iframe node', () => {
25+
const iframe = document.createElement('iframe')
26+
document.body.appendChild(iframe)
27+
iframe.contentDocument.write('<div></div>')
28+
29+
const o = iframe.contentDocument.querySelector('div')
30+
const iframeDocument = iframe.contentDocument
31+
32+
expect(getClosestDocument(o) === iframeDocument).toBeTruthy()
33+
})

0 commit comments

Comments
 (0)