| 1 |
import chai from 'chai'; |
| 2 |
const { expect } = chai; |
| 3 |
import getParentNode from '../../src/utils/getParentNode'; |
| 4 |
|
| 5 |
describe('utils/getParentNode', () => { |
| 6 |
let node; |
| 7 |
|
| 8 |
beforeEach(() => { |
| 9 |
node = document.createElement('div'); |
| 10 |
}); |
| 11 |
|
| 12 |
it('should return parent node', () => { |
| 13 |
const div = document.createElement('div'); |
| 14 |
div.appendChild(node); |
| 15 |
expect(getParentNode(node)).to.equal(div); |
| 16 |
}); |
| 17 |
|
| 18 |
it('should stop at html', () => { |
| 19 |
const html = document.querySelector('html'); |
| 20 |
expect(getParentNode(html)).to.equal(html); |
| 21 |
}); |
| 22 |
|
| 23 |
it('should go outside shadowRoot if possible', () => { |
| 24 |
const div = document.createElement('div'); |
| 25 |
let root; |
| 26 |
if (div.attachShadow) { |
| 27 |
root = div.attachShadow({ mode: 'open' }); |
| 28 |
root.appendChild(node); |
| 29 |
expect(getParentNode(node)).to.equal(root); |
| 30 |
expect(getParentNode(root)).to.equal(div); |
| 31 |
} |
| 32 |
}); |
| 33 |
}); |