0
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-01-09 02:46:15 +01:00
Bootstrap/js/tests/helpers/fixture.js

51 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-03-13 15:23:50 +01:00
const fixtureId = 'fixture'
export const getFixture = () => {
let fixtureEl = document.getElementById(fixtureId)
if (!fixtureEl) {
fixtureEl = document.createElement('div')
fixtureEl.setAttribute('id', fixtureId)
2019-07-22 14:46:03 +02:00
fixtureEl.style.position = 'absolute'
fixtureEl.style.top = '-10000px'
fixtureEl.style.left = '-10000px'
fixtureEl.style.width = '10000px'
fixtureEl.style.height = '10000px'
2019-03-13 15:23:50 +01:00
document.body.appendChild(fixtureEl)
}
return fixtureEl
}
export const clearFixture = () => {
const fixtureEl = getFixture()
fixtureEl.innerHTML = ''
}
2019-03-25 11:32:02 +01:00
2019-08-29 15:20:49 +02:00
export const createEvent = (eventName, params = {}) => {
2019-03-25 11:32:02 +01:00
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)
})
}
}
export const clearBodyAndDocument = () => {
const attributes = ['data-bs-padding-right', 'style']
attributes.forEach(attr => {
document.documentElement.removeAttribute(attr)
document.body.removeAttribute(attr)
})
}