| Total Complexity | 5 |
| Complexity/F | 1 |
| Lines of Code | 38 |
| Function Count | 5 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | import expect from 'expect'; |
||
| 2 | import { elementContains } from './../../src/util/elementContains'; |
||
| 3 | |||
| 4 | describe('elementContains utility function', () => { |
||
| 5 | |||
| 6 | it('Should throw an error for invalid args', () => { |
||
| 7 | expect(() => { |
||
| 8 | elementContains(); |
||
| 9 | }).toThrow('Function requires a dom node and a classname'); |
||
| 10 | }); |
||
| 11 | |||
| 12 | it('Should return true, if element is found', () => { |
||
| 13 | const parent = document.createElement('div'); |
||
| 14 | const node = document.createElement('div'); |
||
| 15 | parent.classList.add('test-class'); |
||
| 16 | |||
| 17 | parent.appendChild(node); |
||
| 18 | document.body.appendChild(parent); |
||
| 19 | |||
| 20 | expect( |
||
| 21 | elementContains(parent, 'test-class') |
||
| 22 | ).toEqual(true); |
||
| 23 | }); |
||
| 24 | |||
| 25 | it('Should return undefined, if not element is found', () => { |
||
| 26 | const parent = document.createElement('div'); |
||
| 27 | const node = document.createElement('div'); |
||
| 28 | parent.classList.add('nope'); |
||
| 29 | |||
| 30 | parent.appendChild(node); |
||
| 31 | document.body.appendChild(parent); |
||
| 32 | |||
| 33 | expect( |
||
| 34 | elementContains(parent, 'test-class') |
||
| 35 | ).toEqual(undefined); |
||
| 36 | }); |
||
| 37 | |||
| 38 | }); |
||
| 39 | |||
| 40 |