diff options
author | Nagarjun Bodduna <boddunan@gmail.com> | 2021-05-10 21:17:53 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-10 21:17:53 +0300 |
commit | 741fa589d027c2d16bff844e45a08c842f5f7e04 (patch) | |
tree | db1823b7d11cd5558d630eaffd64866cdfbef0d5 /js/tests/unit/util | |
parent | 308ffba7930a33b93d0366ad6c19336f907e60da (diff) |
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>
Diffstat (limited to 'js/tests/unit/util')
-rw-r--r-- | js/tests/unit/util/backdrop.spec.js | 72 |
1 files changed, 43 insertions, 29 deletions
diff --git a/js/tests/unit/util/backdrop.spec.js b/js/tests/unit/util/backdrop.spec.js index 0a20a13bc5..ae342b0929 100644 --- a/js/tests/unit/util/backdrop.spec.js +++ b/js/tests/unit/util/backdrop.spec.js @@ -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() + }) + }) + }) }) |