1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-08-09 15:16:51 +02:00

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 <xhmikosr@gmail.com>
Co-authored-by: Rohit Sharma <rohit2sharma95@gmail.com>
This commit is contained in:
Kyle Tsang
2021-02-11 21:51:34 -08:00
committed by GitHub
parent 0a9d392975
commit 02dbd87ffa
8 changed files with 56 additions and 9 deletions

View File

@@ -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
})
})