fixture.js 920 Bytes
Newer Older
Johann-S's avatar
Johann-S committed
1
2
3
4
5
6
7
8
const fixtureId = 'fixture'

export const getFixture = () => {
  let fixtureEl = document.getElementById(fixtureId)

  if (!fixtureEl) {
    fixtureEl = document.createElement('div')
    fixtureEl.setAttribute('id', fixtureId)
Johann-S's avatar
Johann-S committed
9
10
11
12
13
    fixtureEl.style.position = 'absolute'
    fixtureEl.style.top = '-10000px'
    fixtureEl.style.left = '-10000px'
    fixtureEl.style.width = '10000px'
    fixtureEl.style.height = '10000px'
Johann-S's avatar
Johann-S committed
14
15
16
17
18
19
20
21
22
23
24
    document.body.appendChild(fixtureEl)
  }

  return fixtureEl
}

export const clearFixture = () => {
  const fixtureEl = getFixture()

  fixtureEl.innerHTML = ''
}
Johann-S's avatar
Johann-S committed
25

XhmikosR's avatar
XhmikosR committed
26
export const createEvent = (eventName, params = {}) => {
Johann-S's avatar
Johann-S committed
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
  const e = document.createEvent('Event')

  e.initEvent(eventName, Boolean(params.bubbles), Boolean(params.cancelable))
  return e
}

export const jQueryMock = {
  elements: undefined,
  fn: {},
  each(fn) {
    this.elements.forEach(el => {
      fn.call(el)
    })
  }
}