0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-12-05 17:24:20 +01:00
Bootstrap/js/tests/helpers/fixture.js

48 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-03-13 15:23:50 +01:00
const fixtureId = 'fixture'
export const getFixture = () => {
2021-10-29 09:38:35 +02:00
let fixtureElement = document.getElementById(fixtureId)
if (!fixtureElement) {
fixtureElement = document.createElement('div')
fixtureElement.setAttribute('id', fixtureId)
fixtureElement.style.position = 'absolute'
fixtureElement.style.top = '-10000px'
fixtureElement.style.left = '-10000px'
fixtureElement.style.width = '10000px'
fixtureElement.style.height = '10000px'
document.body.append(fixtureElement)
2019-03-13 15:23:50 +01:00
}
2021-10-29 09:38:35 +02:00
return fixtureElement
2019-03-13 15:23:50 +01:00
}
export const clearFixture = () => {
2021-10-29 09:38:35 +02:00
const fixtureElement = getFixture()
2019-03-13 15:23:50 +01:00
2021-10-29 09:38:35 +02:00
fixtureElement.innerHTML = ''
2019-03-13 15:23:50 +01:00
}
2019-03-25 11:32:02 +01:00
2021-10-29 09:38:35 +02:00
export const createEvent = (eventName, parameters = {}) => {
return new Event(eventName, parameters)
2019-03-25 11:32:02 +01:00
}
export const jQueryMock = {
elements: undefined,
fn: {},
each(fn) {
2021-10-29 09:38:35 +02:00
for (const element of this.elements) {
fn.call(element)
}
2019-03-25 11:32:02 +01:00
}
}
export const clearBodyAndDocument = () => {
const attributes = ['data-bs-padding-right', 'style']
2021-10-29 09:38:35 +02:00
for (const attribute of attributes) {
document.documentElement.removeAttribute(attribute)
document.body.removeAttribute(attribute)
}
}