Debian Codegraph @

packages/popper/tests/unit/getOffsetParent.js

raw
1 import chai from 'chai';
2 const { expect } = chai;
3 import getOffsetParent from '../../src/utils/getOffsetParent';
4
5 describe('utils/getOffsetParent', () => {
6 let node;
7
8 beforeEach(() => {
9 node = document.createElement('div');
10 document.body.appendChild(node);
11 });
12
13 afterEach(() => {
14 document.body.removeChild(node);
15 });
16
17 it('element is just appended to the body', () => {
18 expect(getOffsetParent(node)).to.equal(document.querySelector('html'));
19 });
20
21 it('element is inside positioned element', () => {
22 const innerNode = document.createElement('div');
23 node.style.position = 'absolute';
24 node.appendChild(innerNode);
25 expect(getOffsetParent(innerNode)).to.equal(node);
26 });
27
28 it('first child element is hidden', () => {
29 const innerNode = document.createElement('div');
30 innerNode.style.display = 'none';
31 const nextSibling = document.createElement('div');
32 node.style.position = 'absolute';
33 node.appendChild(innerNode);
34 node.appendChild(nextSibling);
35
36 expect(getOffsetParent(innerNode)).to.equal(node);
37 });
38
39 it('all child elements are hidden', () => {
40 const innerNode = document.createElement('div');
41 innerNode.style.display = 'none';
42 node.style.position = 'absolute';
43
44 expect(getOffsetParent(innerNode)).to.equal(document.querySelector('html'));
45 });
46 });