mirror of
https://github.com/twbs/bootstrap.git
synced 2025-01-18 10:52:19 +01:00
Fix backdrop rootElement
not initialized in Modal (#33853)
* Initialize default value of rootElement before using * Remove redundant test | put rootElement tests together Co-authored-by: GeoSot <geo.sotis@gmail.com>
This commit is contained in:
parent
308ffba793
commit
741fa589d0
@ -89,6 +89,8 @@ class Backdrop {
|
||||
...Default,
|
||||
...(typeof config === 'object' ? config : {})
|
||||
}
|
||||
|
||||
config.rootElement = config.rootElement || document.body
|
||||
typeCheckConfig(NAME, config, DefaultType)
|
||||
return config
|
||||
}
|
||||
|
@ -73,35 +73,6 @@ describe('Backdrop', () => {
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('Should be appended on "document.body" by default', done => {
|
||||
const instance = new Backdrop({
|
||||
isVisible: true
|
||||
})
|
||||
const getElement = () => document.querySelector(CLASS_BACKDROP)
|
||||
instance.show(() => {
|
||||
expect(getElement().parentElement).toEqual(document.body)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('Should appended on any element given by the proper config', done => {
|
||||
fixtureEl.innerHTML = [
|
||||
'<div id="wrapper">',
|
||||
'</div>'
|
||||
].join('')
|
||||
|
||||
const wrapper = fixtureEl.querySelector('#wrapper')
|
||||
const instance = new Backdrop({
|
||||
isVisible: true,
|
||||
rootElement: wrapper
|
||||
})
|
||||
const getElement = () => document.querySelector(CLASS_BACKDROP)
|
||||
instance.show(() => {
|
||||
expect(getElement().parentElement).toEqual(wrapper)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('hide', () => {
|
||||
@ -238,4 +209,47 @@ describe('Backdrop', () => {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('rootElement initialization', () => {
|
||||
it('Should be appended on "document.body" by default', done => {
|
||||
const instance = new Backdrop({
|
||||
isVisible: true
|
||||
})
|
||||
const getElement = () => document.querySelector(CLASS_BACKDROP)
|
||||
instance.show(() => {
|
||||
expect(getElement().parentElement).toEqual(document.body)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('Should default parent element to "document.body" when config value is null', done => {
|
||||
const instance = new Backdrop({
|
||||
isVisible: true,
|
||||
rootElement: null
|
||||
})
|
||||
const getElement = () => document.querySelector(CLASS_BACKDROP)
|
||||
instance.show(() => {
|
||||
expect(getElement().parentElement).toEqual(document.body)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('Should appended on any element given by the proper config', done => {
|
||||
fixtureEl.innerHTML = [
|
||||
'<div id="wrapper">',
|
||||
'</div>'
|
||||
].join('')
|
||||
|
||||
const wrapper = fixtureEl.querySelector('#wrapper')
|
||||
const instance = new Backdrop({
|
||||
isVisible: true,
|
||||
rootElement: wrapper
|
||||
})
|
||||
const getElement = () => document.querySelector(CLASS_BACKDROP)
|
||||
instance.show(() => {
|
||||
expect(getElement().parentElement).toEqual(wrapper)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user