diff options
| author | GeoSot <[email protected]> | 2021-02-06 01:04:19 +0200 |
|---|---|---|
| committer | XhmikosR <[email protected]> | 2021-09-07 19:19:12 +0300 |
| commit | a0e5cf46e066eea485704b3d6c932f57e2fa95ac (patch) | |
| tree | 7214962d80b31a9611a23a1cfe28bce85fffa33a /js/tests/unit/carousel.spec.js | |
| parent | 0d81d3cbc14dfcdca8a868e3f25189a4f1ab273c (diff) | |
| download | bootstrap-swipe-events-as-separate-helper.tar.xz bootstrap-swipe-events-as-separate-helper.zip | |
Separate Swipe helper from carouselswipe-events-as-separate-helper
Diffstat (limited to 'js/tests/unit/carousel.spec.js')
| -rw-r--r-- | js/tests/unit/carousel.spec.js | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/js/tests/unit/carousel.spec.js b/js/tests/unit/carousel.spec.js index a933f1eda..dc9f6ec7d 100644 --- a/js/tests/unit/carousel.spec.js +++ b/js/tests/unit/carousel.spec.js @@ -303,23 +303,26 @@ describe('Carousel', () => { }) expect(carousel._addTouchEventListeners).not.toHaveBeenCalled() + expect(carousel._swipeHelper).toBeNull() }) it('should not add touch event listeners if touch supported = false', () => { fixtureEl.innerHTML = '<div></div>' const carouselEl = fixtureEl.querySelector('div') + delete document.documentElement.ontouchstart + Object.defineProperty(window.navigator, 'maxTouchPoints', () => 0) const carousel = new Carousel(carouselEl) - EventHandler.off(carouselEl, '.bs-carousel') - carousel._touchSupported = false + EventHandler.off(carouselEl, Carousel.EVENT_KEY) spyOn(carousel, '_addTouchEventListeners') carousel._addEventListeners() expect(carousel._addTouchEventListeners).not.toHaveBeenCalled() + expect(carousel._swipeHelper).toBeNull() }) it('should add touch event listeners by default', () => { @@ -568,7 +571,7 @@ describe('Carousel', () => { }, () => { restorePointerEvents() delete document.documentElement.ontouchstart - expect(carousel.touchDeltaX).toEqual(0) + expect(carousel._swipeHelper._xDown).toEqual(0) done() }) }) @@ -1239,19 +1242,20 @@ describe('Carousel', () => { const carouselEl = fixtureEl.querySelector('#myCarousel') const addEventSpy = spyOn(carouselEl, 'addEventListener').and.callThrough() - const removeEventSpy = spyOn(carouselEl, 'removeEventListener').and.callThrough() + const removeEventSpy = spyOn(EventHandler, 'off').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) + const swipeHelperSpy = spyOn(carousel._swipeHelper, 'dispose').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)], - ...(carousel._pointerEvent ? + ...(carousel._swipeHelper._supportPointerEvents ? [ ['pointerdown', jasmine.any(Function), jasmine.any(Boolean)], ['pointerup', jasmine.any(Function), jasmine.any(Boolean)] @@ -1267,7 +1271,8 @@ describe('Carousel', () => { carousel.dispose() - expect(removeEventSpy.calls.allArgs()).toEqual(expectedArgs) + expect(removeEventSpy).toHaveBeenCalledWith(carouselEl, Carousel.EVENT_KEY) + expect(swipeHelperSpy).toHaveBeenCalled() delete document.documentElement.ontouchstart }) |
