All files / src tests.js

100% Statements 32/32
100% Branches 0/0
100% Functions 10/10
100% Lines 32/32

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66  1x 1x 1x   1x   1x   1x   1x 1x     1x   1x     1x     1x 1x 1x 1x 1x     1x     1x 1x   1x       1x   1x   1x 1x     1x   1x     1x     1x 1x 1x 1x   1x        
const
assert            = require('chai').assert,
fs                = require('fs'),
path              = require('path')
 
describe('getUniqueCssSelector tests', () =>
{
  describe('getPath tests', () =>
  {
    before(() =>
    {
      const HTML = fs.readFileSync(path.join(__dirname, 'get-selector-test.html'), 'utf-8')
      this.jsdom = require('jsdom-global')(HTML)
    })
 
    after(() =>
    {
      this.jsdom()
    })
 
    it('should get the second topic paragraph', () =>
    {
      const
      getUniqueSelector = require('.'),
      element           = document.querySelectorAll('.topic-title')[1],
      selector          = getUniqueSelector(element),
      domElement        = document.querySelector(selector)
      assert(domElement.isSameNode(element) === true)
    })
 
    it('should return false when element is not HTMLElement', () =>
    {
      const
      getUniqueSelector = require('.'),
      selector          = getUniqueSelector({})
 
      assert(selector === false)
    })
  })
 
  describe('previousSiblingPolyfill tests', () =>
  {
    before(() =>
    {
      const HTML = fs.readFileSync(path.join(__dirname, 'polyfill-test.html'), 'utf-8')
      this.jsdom = require('jsdom-global')(HTML)
    })
 
    after(() =>
    {
      this.jsdom()
    })
 
    it('should get #previous-sibling from #starting-point (separated by text nodes)', () =>
    {
      const
      getPrevious     = require('./previous-sibling-polyfill'),
      element         = window.document.querySelector('#starting-point'),
      previousElement = getPrevious(element),
      previousSibling = document.querySelector('#previous-sibling')
 
      assert(previousElement.isSameNode(previousSibling) === true)
    })
  })
})