aboutsummaryrefslogtreecommitdiff
path: root/js/tests/unit/carousel.spec.js
diff options
context:
space:
mode:
authorKyle Tsang <[email protected]>2021-02-11 21:51:34 -0800
committerGitHub <[email protected]>2021-02-12 07:51:34 +0200
commit02dbd87ffa94ff0d2f5bbc43a13f13033ce01f0b (patch)
treedf0accc46fae8eff5c0f7874c7a2773ac9ec58c4 /js/tests/unit/carousel.spec.js
parent0a9d392975d7f77d8a0e10270da7e07aac013614 (diff)
downloadbootstrap-02dbd87ffa94ff0d2f5bbc43a13f13033ce01f0b.tar.xz
bootstrap-02dbd87ffa94ff0d2f5bbc43a13f13033ce01f0b.zip
Fix event handler removal in dropdown/carousel dispose (#33000)
* Fix event handler removal in carousel dispose * Fix event handler removal in dropdown dispose * Test event handlers in scrollspy dispose * Test event handlers in toast dispose * Test event handlers in tooltip dispose Co-authored-by: XhmikosR <[email protected]> Co-authored-by: Rohit Sharma <[email protected]>
Diffstat (limited to 'js/tests/unit/carousel.spec.js')
-rw-r--r--js/tests/unit/carousel.spec.js23
1 files changed, 21 insertions, 2 deletions
diff --git a/js/tests/unit/carousel.spec.js b/js/tests/unit/carousel.spec.js
index 0571ac9af..5c45efe0c 100644
--- a/js/tests/unit/carousel.spec.js
+++ b/js/tests/unit/carousel.spec.js
@@ -295,6 +295,8 @@ describe('Carousel', () => {
spyOn(Carousel.prototype, '_addTouchEventListeners')
+ // Headless browser does not support touch events, so need to fake it
+ // to test that touch events are add properly.
document.documentElement.ontouchstart = () => {}
const carousel = new Carousel(carouselEl)
@@ -1056,13 +1058,30 @@ describe('Carousel', () => {
].join('')
const carouselEl = fixtureEl.querySelector('#myCarousel')
+ const addEventSpy = spyOn(carouselEl, 'addEventListener').and.callThrough()
+ const removeEventSpy = spyOn(carouselEl, 'removeEventListener').and.callThrough()
+
+ // Headless browser does not support touch events, so need to fake it
+ // to test that touch events are add/removed properly.
+ document.documentElement.ontouchstart = () => {}
+
const carousel = new Carousel(carouselEl)
- spyOn(EventHandler, 'off').and.callThrough()
+ const expectedArgs = [
+ ['keydown', jasmine.any(Function), jasmine.any(Boolean)],
+ ['mouseover', jasmine.any(Function), jasmine.any(Boolean)],
+ ['mouseout', jasmine.any(Function), jasmine.any(Boolean)],
+ ['pointerdown', jasmine.any(Function), jasmine.any(Boolean)],
+ ['pointerup', jasmine.any(Function), jasmine.any(Boolean)]
+ ]
+
+ expect(addEventSpy.calls.allArgs()).toEqual(expectedArgs)
carousel.dispose()
- expect(EventHandler.off).toHaveBeenCalled()
+ expect(removeEventSpy.calls.allArgs()).toEqual(expectedArgs)
+
+ delete document.documentElement.ontouchstart
})
})