blob: 02915af44cb24fe9b007828fdbbe8ced3e9a0c57 (
plain)
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
|
const fixtureId = 'fixture'
export const getFixture = () => {
let fixtureEl = document.getElementById(fixtureId)
if (!fixtureEl) {
fixtureEl = document.createElement('div')
fixtureEl.setAttribute('id', fixtureId)
fixtureEl.style.position = 'absolute'
fixtureEl.style.top = '-10000px'
fixtureEl.style.left = '-10000px'
fixtureEl.style.width = '10000px'
fixtureEl.style.height = '10000px'
document.body.append(fixtureEl)
}
return fixtureEl
}
export const clearFixture = () => {
const fixtureEl = getFixture()
fixtureEl.innerHTML = ''
}
export const createEvent = (eventName, params = {}) => {
const event = document.createEvent('Event')
event.initEvent(eventName, Boolean(params.bubbles), Boolean(params.cancelable))
return event
}
export const jQueryMock = {
elements: undefined,
fn: {},
each(fn) {
for (const el of this.elements) {
fn.call(el)
}
}
}
export const clearBodyAndDocument = () => {
const attributes = ['data-bs-padding-right', 'style']
for (const attr of attributes) {
document.documentElement.removeAttribute(attr)
document.body.removeAttribute(attr)
}
}
|