aboutsummaryrefslogtreecommitdiff
path: root/js/tests/unit
diff options
context:
space:
mode:
authorJérémie Broutier <[email protected]>2022-09-15 12:30:51 +0200
committerGitHub <[email protected]>2022-09-15 13:30:51 +0300
commit6f65df4faea2694840572626f8a02f4399bd0dca (patch)
tree695bdd7d992748fc94c80ba6bd7f7331b1270228 /js/tests/unit
parentaedd7fb9de38efbf6bb4a5443aa870d814df8c55 (diff)
downloadbootstrap-6f65df4faea2694840572626f8a02f4399bd0dca.tar.xz
bootstrap-6f65df4faea2694840572626f8a02f4399bd0dca.zip
Fix modal event listeners (#37128)
* Fix modal event listeners (#37126) Co-authored-by: GeoSot <[email protected]>
Diffstat (limited to 'js/tests/unit')
-rw-r--r--js/tests/unit/modal.spec.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/js/tests/unit/modal.spec.js b/js/tests/unit/modal.spec.js
index e774fc4e8..fdee29e95 100644
--- a/js/tests/unit/modal.spec.js
+++ b/js/tests/unit/modal.spec.js
@@ -734,6 +734,36 @@ describe('Modal', () => {
})
})
+ it('should not close modal when clicking on an element removed from modal content', () => {
+ return new Promise(resolve => {
+ fixtureEl.innerHTML = [
+ '<div class="modal">',
+ ' <div class="modal-dialog">',
+ ' <button class="btn">BTN</button>',
+ ' </div>',
+ '</div>'
+ ].join('')
+
+ const modalEl = fixtureEl.querySelector('.modal')
+ const buttonEl = modalEl.querySelector('.btn')
+ const modal = new Modal(modalEl)
+
+ const spy = spyOn(modal, 'hide')
+ buttonEl.addEventListener('click', () => {
+ buttonEl.remove()
+ })
+
+ modalEl.addEventListener('shown.bs.modal', () => {
+ modalEl.dispatchEvent(createEvent('mousedown'))
+ buttonEl.click()
+ expect(spy).not.toHaveBeenCalled()
+ resolve()
+ })
+
+ modal.show()
+ })
+ })
+
it('should do nothing is the modal is not shown', () => {
fixtureEl.innerHTML = '<div class="modal"><div class="modal-dialog"></div></div>'