0
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-01-18 10:52:19 +01:00

Js: fix some tests

This commit is contained in:
GeoSot 2021-04-12 02:57:53 +03:00 committed by Mark Otto
parent 2120a02b3c
commit 0d440b0e14
3 changed files with 23 additions and 13 deletions

View File

@ -16,6 +16,7 @@ describe('Modal', () => {
clearFixture() clearFixture()
document.body.classList.remove('modal-open') document.body.classList.remove('modal-open')
document.documentElement.removeAttribute('style')
document.body.removeAttribute('style') document.body.removeAttribute('style')
document.body.removeAttribute('data-bs-padding-right') document.body.removeAttribute('data-bs-padding-right')
@ -23,12 +24,12 @@ describe('Modal', () => {
.forEach(backdrop => { .forEach(backdrop => {
document.body.removeChild(backdrop) document.body.removeChild(backdrop)
}) })
document.body.style.removeProperty('paddingRight')
}) })
afterAll(() => { beforeEach(() => {
document.documentElement.style.removeProperty('paddingRight') document.documentElement.removeAttribute('style')
document.body.removeAttribute('style')
document.body.removeAttribute('data-bs-padding-right')
}) })
describe('VERSION', () => { describe('VERSION', () => {
@ -104,7 +105,7 @@ describe('Modal', () => {
const expectedPadding = originalPadding + getScrollBarWidth() const expectedPadding = originalPadding + getScrollBarWidth()
const currentPadding = Number.parseInt(window.getComputedStyle(modalEl).paddingRight, 10) const currentPadding = Number.parseInt(window.getComputedStyle(modalEl).paddingRight, 10)
expect(fixedEl.getAttribute('data-bs-padding-right')).toEqual('0px', 'original fixed element padding should be stored in data-bs-padding-right') expect(fixedEl.getAttribute('data-bs-padding-right')).toEqual(`${originalPadding}px`, 'original fixed element padding should be stored in data-bs-padding-right')
expect(currentPadding).toEqual(expectedPadding, 'fixed element padding should be adjusted while opening') expect(currentPadding).toEqual(expectedPadding, 'fixed element padding should be adjusted while opening')
modal.toggle() modal.toggle()
}) })
@ -112,7 +113,7 @@ describe('Modal', () => {
modalEl.addEventListener('hidden.bs.modal', () => { modalEl.addEventListener('hidden.bs.modal', () => {
const currentPadding = Number.parseInt(window.getComputedStyle(modalEl).paddingRight, 10) const currentPadding = Number.parseInt(window.getComputedStyle(modalEl).paddingRight, 10)
expect(fixedEl.getAttribute('data-bs-padding-right')).toEqual(null, 'data-bs-padding-right should be cleared after closing') expect(fixedEl.hasAttribute('data-bs-padding-right')).toEqual(false, 'data-bs-padding-right should be cleared after closing')
expect(currentPadding).toEqual(originalPadding, 'fixed element padding should be reset after closing') expect(currentPadding).toEqual(originalPadding, 'fixed element padding should be reset after closing')
document.documentElement.style.overflowY = 'auto' document.documentElement.style.overflowY = 'auto'
done() done()
@ -138,7 +139,7 @@ describe('Modal', () => {
const expectedMargin = originalMargin - getScrollBarWidth() const expectedMargin = originalMargin - getScrollBarWidth()
const currentMargin = Number.parseInt(window.getComputedStyle(stickyTopEl).marginRight, 10) const currentMargin = Number.parseInt(window.getComputedStyle(stickyTopEl).marginRight, 10)
expect(stickyTopEl.getAttribute('data-bs-margin-right')).toEqual('0px', 'original sticky element margin should be stored in data-bs-margin-right') expect(stickyTopEl.getAttribute('data-bs-margin-right')).toEqual(`${originalMargin}px`, 'original sticky element margin should be stored in data-bs-margin-right')
expect(currentMargin).toEqual(expectedMargin, 'sticky element margin should be adjusted while opening') expect(currentMargin).toEqual(expectedMargin, 'sticky element margin should be adjusted while opening')
modal.toggle() modal.toggle()
}) })
@ -146,7 +147,7 @@ describe('Modal', () => {
modalEl.addEventListener('hidden.bs.modal', () => { modalEl.addEventListener('hidden.bs.modal', () => {
const currentMargin = Number.parseInt(window.getComputedStyle(stickyTopEl).marginRight, 10) const currentMargin = Number.parseInt(window.getComputedStyle(stickyTopEl).marginRight, 10)
expect(stickyTopEl.getAttribute('data-bs-margin-right')).toEqual(null, 'data-bs-margin-right should be cleared after closing') expect(stickyTopEl.hasAttribute('data-bs-margin-right')).toEqual(false, 'data-bs-margin-right should be cleared after closing')
expect(currentMargin).toEqual(originalMargin, 'sticky element margin should be reset after closing') expect(currentMargin).toEqual(originalMargin, 'sticky element margin should be reset after closing')
document.documentElement.style.overflowY = 'auto' document.documentElement.style.overflowY = 'auto'
@ -679,7 +680,6 @@ describe('Modal', () => {
// Restore scrollbars // Restore scrollbars
document.body.style.overflow = 'auto' document.body.style.overflow = 'auto'
document.documentElement.style.paddingRight = '16px'
done() done()
}) })
@ -711,7 +711,6 @@ describe('Modal', () => {
// Restore overridden css // Restore overridden css
document.body.style.removeProperty('margin') document.body.style.removeProperty('margin')
document.body.style.removeProperty('overflow') document.body.style.removeProperty('overflow')
document.documentElement.style.paddingRight = '16px'
done() done()
}) })

View File

@ -14,6 +14,15 @@ describe('Offcanvas', () => {
afterEach(() => { afterEach(() => {
clearFixture() clearFixture()
document.body.classList.remove('offcanvas-open') document.body.classList.remove('offcanvas-open')
document.documentElement.removeAttribute('style')
document.body.removeAttribute('style')
document.body.removeAttribute('data-bs-padding-right')
})
beforeEach(() => {
document.documentElement.removeAttribute('style')
document.body.removeAttribute('style')
document.body.removeAttribute('data-bs-padding-right')
}) })
describe('VERSION', () => { describe('VERSION', () => {
@ -177,7 +186,7 @@ describe('Offcanvas', () => {
offCanvas.hide() offCanvas.hide()
}) })
offCanvasEl.addEventListener('hidden.bs.offcanvas', () => { offCanvasEl.addEventListener('hidden.bs.offcanvas', () => {
expect(document.body.style.overflow).toEqual('auto') expect(document.body.style.overflow).not.toEqual('hidden')
done() done()
}) })
offCanvas.show() offCanvas.show()

View File

@ -28,17 +28,19 @@ describe('ScrollBar', () => {
afterAll(() => { afterAll(() => {
fixtureEl.remove() fixtureEl.remove()
document.documentElement.style.overflowY = 'auto'
document.body.style.overflowY = 'auto'
}) })
afterEach(() => { afterEach(() => {
clearFixture() clearFixture()
document.documentElement.removeAttribute('style') document.documentElement.removeAttribute('style')
document.body.removeAttribute('style')
document.body.removeAttribute('data-bs-padding-right')
}) })
beforeEach(() => { beforeEach(() => {
document.documentElement.removeAttribute('style') document.documentElement.removeAttribute('style')
document.body.removeAttribute('style')
document.body.removeAttribute('data-bs-padding-right')
}) })
describe('isBodyOverflowing', () => { describe('isBodyOverflowing', () => {