const alertEl = fixtureEl.querySelector('.alert')
const alert = new Alert(alertEl)
- spyOn(alert, 'close')
+ const spy = spyOn(alert, 'close')
jQueryMock.fn.alert = Alert.jQueryInterface
jQueryMock.elements = [alertEl]
jQueryMock.fn.alert.call(jQueryMock, 'close')
- expect(alert.close).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
})
it('should create new alert instance and call close', () => {
it('should de-register element event listeners', () => {
createInstance()
- spyOn(EventHandler, 'off')
+ const spy = spyOn(EventHandler, 'off')
instance.dispose()
- expect(EventHandler.off).toHaveBeenCalledWith(element, DummyClass.EVENT_KEY)
+ expect(spy).toHaveBeenCalledWith(element, DummyClass.EVENT_KEY)
})
})
const btnEl = fixtureEl.querySelector('.btn')
const button = new Button(btnEl)
- spyOn(button, 'toggle')
+ const spy = spyOn(button, 'toggle')
jQueryMock.fn.button = Button.jQueryInterface
jQueryMock.elements = [btnEl]
jQueryMock.fn.button.call(jQueryMock, 'toggle')
- expect(button.toggle).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
})
it('should create new button instance and call toggle', () => {
keyboard: true
})
- spyOn(carousel, '_keydown').and.callThrough()
+ const spy = spyOn(carousel, '_keydown').and.callThrough()
carouselEl.addEventListener('slid.bs.carousel', () => {
expect(fixtureEl.querySelector('.active')).toEqual(fixtureEl.querySelector('#item2'))
- expect(carousel._keydown).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
resolve()
})
'</div>'
].join('')
- spyOn(EventHandler, 'trigger').and.callThrough()
+ const spy = spyOn(EventHandler, 'trigger').and.callThrough()
const carouselEl = fixtureEl.querySelector('#myCarousel')
// eslint-disable-next-line no-new
new Carousel('#myCarousel')
- expect(EventHandler.trigger).not.toHaveBeenCalledWith(carouselEl, 'keydown.bs.carousel', jasmine.any(Function))
+ expect(spy).not.toHaveBeenCalledWith(carouselEl, 'keydown.bs.carousel', jasmine.any(Function))
})
it('should ignore mouse events if data-bs-pause=false', () => {
'</div>'
].join('')
- spyOn(EventHandler, 'trigger').and.callThrough()
+ const spy = spyOn(EventHandler, 'trigger').and.callThrough()
const carouselEl = fixtureEl.querySelector('#myCarousel')
// eslint-disable-next-line no-new
new Carousel('#myCarousel')
- expect(EventHandler.trigger).not.toHaveBeenCalledWith(carouselEl, 'hover.bs.carousel', jasmine.any(Function))
+ expect(spy).not.toHaveBeenCalledWith(carouselEl, 'hover.bs.carousel', jasmine.any(Function))
})
it('should go to previous item if left arrow key is pressed', () => {
keyboard: true
})
- spyOn(carousel, '_keydown').and.callThrough()
+ const spy = spyOn(carousel, '_keydown').and.callThrough()
carouselEl.addEventListener('slid.bs.carousel', () => {
expect(fixtureEl.querySelector('.active')).toEqual(fixtureEl.querySelector('#item1'))
- expect(carousel._keydown).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
resolve()
})
keyboard: true
})
- spyOn(carousel, '_keydown').and.callThrough()
+ const spy = spyOn(carousel, '_keydown').and.callThrough()
carouselEl.addEventListener('keydown', event => {
- expect(carousel._keydown).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
expect(event.defaultPrevented).toBeFalse()
resolve()
})
const carouselEl = fixtureEl.querySelector('div')
const carousel = new Carousel(carouselEl, {})
- spyOn(EventHandler, 'trigger')
+ const spy = spyOn(EventHandler, 'trigger')
carousel._isSliding = true
carouselEl.dispatchEvent(keydown)
}
- expect(EventHandler.trigger).not.toHaveBeenCalled()
+ expect(spy).not.toHaveBeenCalled()
})
it('should wrap around from end to start when wrap option is true', () => {
const carouselEl = fixtureEl.querySelector('div')
- spyOn(Carousel.prototype, '_addTouchEventListeners')
+ const spy = spyOn(Carousel.prototype, '_addTouchEventListeners')
const carousel = new Carousel(carouselEl, {
touch: false
})
- expect(carousel._addTouchEventListeners).not.toHaveBeenCalled()
+ expect(spy).not.toHaveBeenCalled()
expect(carousel._swipeHelper).toBeNull()
})
const carousel = new Carousel(carouselEl)
EventHandler.off(carouselEl, Carousel.EVENT_KEY)
- spyOn(carousel, '_addTouchEventListeners')
+ const spy = spyOn(carousel, '_addTouchEventListeners')
carousel._addEventListeners()
- expect(carousel._addTouchEventListeners).not.toHaveBeenCalled()
+ expect(spy).not.toHaveBeenCalled()
expect(carousel._swipeHelper).toBeNull()
})
const item = fixtureEl.querySelector('#item')
const carousel = new Carousel(carouselEl)
- spyOn(carousel, '_slide').and.callThrough()
+ const spy = spyOn(carousel, '_slide').and.callThrough()
carouselEl.addEventListener('slid.bs.carousel', event => {
expect(item).toHaveClass('active')
- expect(carousel._slide).toHaveBeenCalledWith('prev')
+ expect(spy).toHaveBeenCalledWith('prev')
expect(event.direction).toEqual('right')
stylesCarousel.remove()
delete document.documentElement.ontouchstart
const item = fixtureEl.querySelector('#item')
const carousel = new Carousel(carouselEl)
- spyOn(carousel, '_slide').and.callThrough()
+ const spy = spyOn(carousel, '_slide').and.callThrough()
carouselEl.addEventListener('slid.bs.carousel', event => {
expect(item).not.toHaveClass('active')
- expect(carousel._slide).toHaveBeenCalledWith('next')
+ expect(spy).toHaveBeenCalledWith('next')
expect(event.direction).toEqual('left')
stylesCarousel.remove()
delete document.documentElement.ontouchstart
const item = fixtureEl.querySelector('#item')
const carousel = new Carousel(carouselEl)
- spyOn(carousel, '_slide').and.callThrough()
+ const spy = spyOn(carousel, '_slide').and.callThrough()
carouselEl.addEventListener('slid.bs.carousel', event => {
expect(item).toHaveClass('active')
- expect(carousel._slide).toHaveBeenCalledWith('prev')
+ expect(spy).toHaveBeenCalledWith('prev')
expect(event.direction).toEqual('right')
delete document.documentElement.ontouchstart
restorePointerEvents()
const item = fixtureEl.querySelector('#item')
const carousel = new Carousel(carouselEl)
- spyOn(carousel, '_slide').and.callThrough()
+ const spy = spyOn(carousel, '_slide').and.callThrough()
carouselEl.addEventListener('slid.bs.carousel', event => {
expect(item).not.toHaveClass('active')
- expect(carousel._slide).toHaveBeenCalledWith('next')
+ expect(spy).toHaveBeenCalledWith('next')
expect(event.direction).toEqual('left')
delete document.documentElement.ontouchstart
restorePointerEvents()
const carousel = new Carousel(carouselEl)
carousel._isSliding = true
- spyOn(EventHandler, 'trigger')
+ const spy = spyOn(EventHandler, 'trigger')
Simulator.gestures.swipe(carouselEl, {
deltaX: 300,
})
setTimeout(() => {
- expect(EventHandler.trigger).not.toHaveBeenCalled()
+ expect(spy).not.toHaveBeenCalled()
delete document.documentElement.ontouchstart
restorePointerEvents()
resolve()
const carouselEl = fixtureEl.querySelector('.carousel')
const carousel = new Carousel(carouselEl)
- spyOn(carousel, 'pause')
+ const spy = spyOn(carousel, 'pause')
const mouseOverEvent = createEvent('mouseover')
carouselEl.dispatchEvent(mouseOverEvent)
setTimeout(() => {
- expect(carousel.pause).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
resolve()
}, 10)
})
})
- it('should call `maybeCycle` on mouse out with pause equal to hover', () => {
+ it('should call `maybeEnableCycle` on mouse out with pause equal to hover', () => {
return new Promise(resolve => {
fixtureEl.innerHTML = '<div class="carousel" data-bs-ride="true"></div>'
const carouselEl = fixtureEl.querySelector('.carousel')
const carousel = new Carousel(carouselEl)
- spyOn(carousel, '_maybeEnableCycle').and.callThrough()
- spyOn(carousel, 'cycle')
+ const spyEnable = spyOn(carousel, '_maybeEnableCycle').and.callThrough()
+ const spyCycle = spyOn(carousel, 'cycle')
const mouseOutEvent = createEvent('mouseout')
carouselEl.dispatchEvent(mouseOutEvent)
setTimeout(() => {
- expect(carousel._maybeEnableCycle).toHaveBeenCalled()
- expect(carousel.cycle).toHaveBeenCalled()
+ expect(spyEnable).toHaveBeenCalled()
+ expect(spyCycle).toHaveBeenCalled()
resolve()
}, 10)
})
const carouselEl = fixtureEl.querySelector('div')
const carousel = new Carousel(carouselEl, {})
- spyOn(EventHandler, 'trigger')
+ const spy = spyOn(EventHandler, 'trigger')
carousel._isSliding = true
carousel.next()
- expect(EventHandler.trigger).not.toHaveBeenCalled()
+ expect(spy).not.toHaveBeenCalled()
})
it('should not fire slid when slide is prevented', () => {
const carouselEl = fixtureEl.querySelector('#myCarousel')
const carousel = new Carousel(carouselEl)
- spyOn(carousel, 'cycle')
+ const spy = spyOn(carousel, 'cycle')
carousel.next()
- expect(carousel.cycle).not.toHaveBeenCalled()
+ expect(spy).not.toHaveBeenCalled()
carousel.cycle()
carousel.next()
- expect(carousel.cycle).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalledTimes(1)
})
it('should update indicators if present', () => {
const carousel = new Carousel(carouselEl)
const nextSpy = spyOn(carousel, 'next')
const prevSpy = spyOn(carousel, 'prev')
- spyOn(carousel, '_maybeEnableCycle')
+ const spyEnable = spyOn(carousel, '_maybeEnableCycle')
nextBtnEl.click()
prevBtnEl.click()
expect(nextSpy).toHaveBeenCalled()
expect(prevSpy).toHaveBeenCalled()
- expect(carousel._maybeEnableCycle).toHaveBeenCalled()
+ expect(spyEnable).toHaveBeenCalled()
})
})
const carouselEl = fixtureEl.querySelector('.carousel')
const carousel = new Carousel(carouselEl)
- spyOn(carousel, 'next')
+ const spy = spyOn(carousel, 'next')
carousel.nextWhenVisible()
- expect(carousel.next).not.toHaveBeenCalled()
+ expect(spy).not.toHaveBeenCalled()
})
})
const carouselEl = fixtureEl.querySelector('div')
const carousel = new Carousel(carouselEl, {})
- spyOn(EventHandler, 'trigger')
+ const spy = spyOn(EventHandler, 'trigger')
carousel._isSliding = true
carousel.prev()
- expect(EventHandler.trigger).not.toHaveBeenCalled()
+ expect(spy).not.toHaveBeenCalled()
})
})
const carouselEl = fixtureEl.querySelector('#myCarousel')
const carousel = new Carousel(carouselEl)
+ const spy = spyOn(carousel, '_clearInterval')
carouselEl.addEventListener('transitionend', () => {
- expect(carousel._clearInterval).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
resolve()
})
- spyOn(carousel, '_clearInterval')
carousel._slide('next')
carousel.pause()
})
const carouselEl = fixtureEl.querySelector('#myCarousel')
const carousel = new Carousel(carouselEl)
- spyOn(window, 'setInterval').and.callThrough()
+ const spy = spyOn(window, 'setInterval').and.callThrough()
carousel.cycle()
- expect(window.setInterval).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
})
it('should clear interval if there is one', () => {
carousel._interval = setInterval(noop, 10)
- spyOn(window, 'setInterval').and.callThrough()
- spyOn(window, 'clearInterval').and.callThrough()
+ const spySet = spyOn(window, 'setInterval').and.callThrough()
+ const spyClear = spyOn(window, 'clearInterval').and.callThrough()
carousel.cycle()
- expect(window.setInterval).toHaveBeenCalled()
- expect(window.clearInterval).toHaveBeenCalled()
+ expect(spySet).toHaveBeenCalled()
+ expect(spyClear).toHaveBeenCalled()
})
it('should get interval from data attribute on the active item element', () => {
const carouselEl = fixtureEl.querySelector('#myCarousel')
const carousel = new Carousel(carouselEl, {})
- spyOn(carousel, '_slide')
- spyOn(carousel, 'pause')
- spyOn(carousel, 'cycle')
+ const spy = spyOn(carousel, '_slide')
carousel.to(0)
- expect(carousel._slide).not.toHaveBeenCalled()
+ expect(spy).not.toHaveBeenCalled()
})
it('should wait before performing to if a slide is sliding', () => {
const carouselEl = fixtureEl.querySelector('#myCarousel')
const carousel = new Carousel(carouselEl, {})
- spyOn(EventHandler, 'one').and.callThrough()
- spyOn(carousel, '_slide')
+ const spyOne = spyOn(EventHandler, 'one').and.callThrough()
+ const spySlide = spyOn(carousel, '_slide')
carousel._isSliding = true
carousel.to(1)
- expect(carousel._slide).not.toHaveBeenCalled()
- expect(EventHandler.one).toHaveBeenCalled()
+ expect(spySlide).not.toHaveBeenCalled()
+ expect(spyOne).toHaveBeenCalled()
- spyOn(carousel, 'to')
+ const spyTo = spyOn(carousel, 'to')
EventHandler.trigger(carouselEl, 'slid.bs.carousel')
setTimeout(() => {
- expect(carousel.to).toHaveBeenCalledWith(1)
+ expect(spyTo).toHaveBeenCalledWith(1)
resolve()
})
})
const carousel = new Carousel(div)
const slideTo = 2
- spyOn(carousel, 'to')
+ const spy = spyOn(carousel, 'to')
jQueryMock.fn.carousel = Carousel.jQueryInterface
jQueryMock.elements = [div]
jQueryMock.fn.carousel.call(jQueryMock, slideTo)
- expect(carousel.to).toHaveBeenCalledWith(slideTo)
+ expect(spy).toHaveBeenCalledWith(slideTo)
})
it('should throw error on undefined method', () => {
const collapseEl = fixtureEl.querySelector('div')
const collapse = new Collapse(collapseEl)
- spyOn(collapse, 'show')
+ const spy = spyOn(collapse, 'show')
collapse.toggle()
- expect(collapse.show).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
})
it('should call hide method if show class is present', () => {
toggle: false
})
- spyOn(collapse, 'hide')
+ const spy = spyOn(collapse, 'hide')
collapse.toggle()
- expect(collapse.hide).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
})
it('should find collapse children if they have collapse class too not only data-bs-parent', () => {
it('should do nothing if is transitioning', () => {
fixtureEl.innerHTML = '<div></div>'
- spyOn(EventHandler, 'trigger')
+ const spy = spyOn(EventHandler, 'trigger')
const collapseEl = fixtureEl.querySelector('div')
const collapse = new Collapse(collapseEl, {
collapse._isTransitioning = true
collapse.show()
- expect(EventHandler.trigger).not.toHaveBeenCalled()
+ expect(spy).not.toHaveBeenCalled()
})
it('should do nothing if already shown', () => {
fixtureEl.innerHTML = '<div class="show"></div>'
- spyOn(EventHandler, 'trigger')
+ const spy = spyOn(EventHandler, 'trigger')
const collapseEl = fixtureEl.querySelector('div')
const collapse = new Collapse(collapseEl, {
collapse.show()
- expect(EventHandler.trigger).not.toHaveBeenCalled()
+ expect(spy).not.toHaveBeenCalled()
})
it('should show a collapsed element', () => {
it('should do nothing if is transitioning', () => {
fixtureEl.innerHTML = '<div></div>'
- spyOn(EventHandler, 'trigger')
+ const spy = spyOn(EventHandler, 'trigger')
const collapseEl = fixtureEl.querySelector('div')
const collapse = new Collapse(collapseEl, {
collapse._isTransitioning = true
collapse.hide()
- expect(EventHandler.trigger).not.toHaveBeenCalled()
+ expect(spy).not.toHaveBeenCalled()
})
it('should do nothing if already shown', () => {
fixtureEl.innerHTML = '<div></div>'
- spyOn(EventHandler, 'trigger')
+ const spy = spyOn(EventHandler, 'trigger')
const collapseEl = fixtureEl.querySelector('div')
const collapse = new Collapse(collapseEl, {
collapse.hide()
- expect(EventHandler.trigger).not.toHaveBeenCalled()
+ expect(spy).not.toHaveBeenCalled()
})
it('should hide a collapsed element', () => {
const triggerEl = fixtureEl.querySelector('a')
const nestedTriggerEl = fixtureEl.querySelector('#nested')
- spyOn(Event.prototype, 'preventDefault').and.callThrough()
+ const spy = spyOn(Event.prototype, 'preventDefault').and.callThrough()
triggerEl.addEventListener('click', event => {
expect(event.target.isEqualNode(nestedTriggerEl)).toBeTrue()
expect(event.delegateTarget.isEqualNode(triggerEl)).toBeTrue()
- expect(Event.prototype.preventDefault).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
resolve()
})
const dropdown = new Dropdown(btnDropdown)
document.documentElement.ontouchstart = noop
- spyOn(EventHandler, 'on')
- spyOn(EventHandler, 'off')
+ const spy = spyOn(EventHandler, 'on')
+ const spyOff = spyOn(EventHandler, 'off')
btnDropdown.addEventListener('shown.bs.dropdown', () => {
expect(btnDropdown).toHaveClass('show')
expect(btnDropdown.getAttribute('aria-expanded')).toEqual('true')
- expect(EventHandler.on).toHaveBeenCalledWith(jasmine.any(Object), 'mouseover', noop)
+ expect(spy).toHaveBeenCalledWith(jasmine.any(Object), 'mouseover', noop)
dropdown.toggle()
})
btnDropdown.addEventListener('hidden.bs.dropdown', () => {
expect(btnDropdown).not.toHaveClass('show')
expect(btnDropdown.getAttribute('aria-expanded')).toEqual('false')
- expect(EventHandler.off).toHaveBeenCalledWith(jasmine.any(Object), 'mouseover', noop)
+ expect(spyOff).toHaveBeenCalledWith(jasmine.any(Object), 'mouseover', noop)
document.documentElement.ontouchstart = defaultValueOnTouchStart
resolve()
reference: virtualElement,
popperConfig: {
onFirstUpdate() {
- expect(virtualElement.getBoundingClientRect).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
expect(btnDropdown).toHaveClass('show')
expect(btnDropdown.getAttribute('aria-expanded')).toEqual('true')
resolve()
}
})
- spyOn(virtualElement, 'getBoundingClientRect').and.callThrough()
+ const spy = spyOn(virtualElement, 'getBoundingClientRect').and.callThrough()
dropdown.toggle()
})
const dropdown = new Dropdown(btnDropdown)
document.documentElement.ontouchstart = noop
- spyOn(EventHandler, 'off')
+ const spy = spyOn(EventHandler, 'off')
btnDropdown.addEventListener('shown.bs.dropdown', () => {
dropdown.hide()
btnDropdown.addEventListener('hidden.bs.dropdown', () => {
expect(btnDropdown).not.toHaveClass('show')
expect(btnDropdown.getAttribute('aria-expanded')).toEqual('false')
- expect(EventHandler.off).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
document.documentElement.ontouchstart = defaultValueOnTouchStart
resolve()
expect(dropdown._popper).toBeNull()
expect(dropdown._menu).not.toBeNull()
expect(dropdown._element).not.toBeNull()
- spyOn(EventHandler, 'off')
+ const spy = spyOn(EventHandler, 'off')
dropdown.dispose()
expect(dropdown._menu).toBeNull()
expect(dropdown._element).toBeNull()
- expect(EventHandler.off).toHaveBeenCalledWith(btnDropdown, Dropdown.EVENT_KEY)
+ expect(spy).toHaveBeenCalledWith(btnDropdown, Dropdown.EVENT_KEY)
})
it('should dispose dropdown with Popper', () => {
expect(dropdown._popper).not.toBeNull()
- spyOn(dropdown._popper, 'update')
- spyOn(dropdown, '_detectNavbar')
+ const spyUpdate = spyOn(dropdown._popper, 'update')
+ const spyDetect = spyOn(dropdown, '_detectNavbar')
dropdown.update()
- expect(dropdown._popper.update).toHaveBeenCalled()
- expect(dropdown._detectNavbar).toHaveBeenCalled()
+ expect(spyUpdate).toHaveBeenCalled()
+ expect(spyDetect).toHaveBeenCalled()
})
it('should just detect navbar on update', () => {
const btnDropdown = fixtureEl.querySelector('[data-bs-toggle="dropdown"]')
const dropdown = new Dropdown(btnDropdown)
- spyOn(dropdown, '_detectNavbar')
+ const spy = spyOn(dropdown, '_detectNavbar')
dropdown.update()
expect(dropdown._popper).toBeNull()
- expect(dropdown._detectNavbar).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
})
})
const dropdown = new Dropdown(triggerDropdown)
const button = fixtureEl.querySelector('button[data-bs-toggle="dropdown"]')
- spyOn(dropdown, 'toggle')
+ const spy = spyOn(dropdown, 'toggle')
// Key escape
button.focus()
button.dispatchEvent(keydownEscape)
setTimeout(() => {
- expect(dropdown.toggle).not.toHaveBeenCalled()
+ expect(spy).not.toHaveBeenCalled()
expect(triggerDropdown).not.toHaveClass('show')
resolve()
}, 20)
return new Promise(resolve => {
fixtureEl.innerHTML = '<div class="modal"><div class="modal-dialog"></div></div>'
- spyOn(ScrollBarHelper.prototype, 'hide').and.callThrough()
- spyOn(ScrollBarHelper.prototype, 'reset').and.callThrough()
+ const spyHide = spyOn(ScrollBarHelper.prototype, 'hide').and.callThrough()
+ const spyReset = spyOn(ScrollBarHelper.prototype, 'reset').and.callThrough()
const modalEl = fixtureEl.querySelector('.modal')
const modal = new Modal(modalEl)
modalEl.addEventListener('shown.bs.modal', () => {
- expect(ScrollBarHelper.prototype.hide).toHaveBeenCalled()
+ expect(spyHide).toHaveBeenCalled()
modal.toggle()
})
modalEl.addEventListener('hidden.bs.modal', () => {
- expect(ScrollBarHelper.prototype.reset).toHaveBeenCalled()
+ expect(spyReset).toHaveBeenCalled()
resolve()
})
const modalEl = fixtureEl.querySelector('.modal')
const modal = new Modal(modalEl)
- spyOn(EventHandler, 'trigger')
+ const spy = spyOn(EventHandler, 'trigger')
modal._isShown = true
modal.show()
- expect(EventHandler.trigger).not.toHaveBeenCalled()
+ expect(spy).not.toHaveBeenCalled()
})
it('should do nothing if a modal is transitioning', () => {
const modalEl = fixtureEl.querySelector('.modal')
const modal = new Modal(modalEl)
- spyOn(EventHandler, 'trigger')
+ const spy = spyOn(EventHandler, 'trigger')
modal._isTransitioning = true
modal.show()
- expect(EventHandler.trigger).not.toHaveBeenCalled()
+ expect(spy).not.toHaveBeenCalled()
})
it('should not fire shown event when show is prevented', () => {
const btnClose = fixtureEl.querySelector('[data-bs-dismiss="modal"]')
const modal = new Modal(modalEl)
- spyOn(modal, 'hide').and.callThrough()
+ const spy = spyOn(modal, 'hide').and.callThrough()
modalEl.addEventListener('shown.bs.modal', () => {
btnClose.click()
})
modalEl.addEventListener('hidden.bs.modal', () => {
- expect(modal.hide).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
resolve()
})
const btnClose = fixtureEl.querySelector('[data-bs-dismiss="modal"]')
const modal = new Modal(modalEl)
- spyOn(modal, 'hide').and.callThrough()
+ const spy = spyOn(modal, 'hide').and.callThrough()
modalEl.addEventListener('shown.bs.modal', () => {
btnClose.click()
})
modalEl.addEventListener('hidden.bs.modal', () => {
- expect(modal.hide).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
resolve()
})
focus: false
})
- spyOn(modal._focustrap, 'activate').and.callThrough()
+ const spy = spyOn(modal._focustrap, 'activate').and.callThrough()
modalEl.addEventListener('shown.bs.modal', () => {
- expect(modal._focustrap.activate).not.toHaveBeenCalled()
+ expect(spy).not.toHaveBeenCalled()
resolve()
})
const modalEl = fixtureEl.querySelector('.modal')
const modal = new Modal(modalEl)
- spyOn(modal, 'hide').and.callThrough()
+ const spy = spyOn(modal, 'hide').and.callThrough()
modalEl.addEventListener('shown.bs.modal', () => {
const keydownEscape = createEvent('keydown')
})
modalEl.addEventListener('hidden.bs.modal', () => {
- expect(modal.hide).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
resolve()
})
const modalEl = fixtureEl.querySelector('.modal')
const modal = new Modal(modalEl)
- spyOn(modal, 'hide')
+ const spy = spyOn(modal, 'hide')
const expectDone = () => {
- expect(modal.hide).not.toHaveBeenCalled()
+ expect(spy).not.toHaveBeenCalled()
resolve()
}
const modalEl = fixtureEl.querySelector('.modal')
const modal = new Modal(modalEl)
- spyOn(modal._focustrap, 'activate').and.callThrough()
+ const spy = spyOn(modal._focustrap, 'activate').and.callThrough()
modalEl.addEventListener('shown.bs.modal', () => {
- expect(modal._focustrap.activate).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
resolve()
})
const modalEl = fixtureEl.querySelector('.modal')
const modal = new Modal(modalEl)
- spyOn(modal._focustrap, 'deactivate').and.callThrough()
+ const spy = spyOn(modal._focustrap, 'deactivate').and.callThrough()
modalEl.addEventListener('shown.bs.modal', () => {
modal.hide()
})
modalEl.addEventListener('hidden.bs.modal', () => {
- expect(modal._focustrap.deactivate).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
resolve()
})
const modalEl = fixtureEl.querySelector('.modal')
const modal = new Modal(modalEl)
const focustrap = modal._focustrap
- spyOn(focustrap, 'deactivate').and.callThrough()
+ const spyDeactivate = spyOn(focustrap, 'deactivate').and.callThrough()
expect(Modal.getInstance(modalEl)).toEqual(modal)
- spyOn(EventHandler, 'off')
+ const spyOff = spyOn(EventHandler, 'off')
modal.dispose()
expect(Modal.getInstance(modalEl)).toBeNull()
- expect(EventHandler.off).toHaveBeenCalledTimes(3)
- expect(focustrap.deactivate).toHaveBeenCalled()
+ expect(spyOff).toHaveBeenCalledTimes(3)
+ expect(spyDeactivate).toHaveBeenCalled()
})
})
const modalEl = fixtureEl.querySelector('.modal')
const modal = new Modal(modalEl)
- spyOn(modal, '_adjustDialog')
+ const spy = spyOn(modal, '_adjustDialog')
modal.handleUpdate()
- expect(modal._adjustDialog).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
})
})
const modal = new Modal(modalEl)
const trigger = fixtureEl.querySelector('[data-bs-toggle="modal"]')
- spyOn(modal, 'show').and.callThrough()
+ const spy = spyOn(modal, 'show').and.callThrough()
modalEl.addEventListener('shown.bs.modal', () => {
- expect(modal.show).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
resolve()
})
const modalEl = fixtureEl.querySelector('.modal')
const trigger = fixtureEl.querySelector('[data-bs-toggle="modal"]')
- spyOn(Event.prototype, 'preventDefault').and.callThrough()
+ const spy = spyOn(Event.prototype, 'preventDefault').and.callThrough()
modalEl.addEventListener('shown.bs.modal', () => {
expect(modalEl.getAttribute('aria-modal')).toEqual('true')
expect(modalEl.getAttribute('aria-hidden')).toBeNull()
expect(modalEl.style.display).toEqual('block')
expect(document.querySelector('.modal-backdrop')).not.toBeNull()
- expect(Event.prototype.preventDefault).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
resolve()
})
const modalEl = fixtureEl.querySelector('.modal')
const trigger = fixtureEl.querySelector('[data-bs-toggle="modal"]')
- spyOn(trigger, 'focus')
+ const spy = spyOn(trigger, 'focus')
modalEl.addEventListener('shown.bs.modal', () => {
const modal = Modal.getInstance(modalEl)
const hideListener = () => {
setTimeout(() => {
- expect(trigger.focus).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
resolve()
}, 20)
}
const btnClose = fixtureEl.querySelector('button[data-bs-dismiss="modal"]')
const modal = new Modal(modalEl)
- spyOn(Event.prototype, 'preventDefault').and.callThrough()
+ const spy = spyOn(Event.prototype, 'preventDefault').and.callThrough()
modalEl.addEventListener('shown.bs.modal', () => {
btnClose.click()
})
modalEl.addEventListener('hidden.bs.modal', () => {
- expect(Event.prototype.preventDefault).not.toHaveBeenCalled()
+ expect(spy).not.toHaveBeenCalled()
resolve()
})
const btnClose = fixtureEl.querySelector('a[data-bs-dismiss="modal"]')
const modal = new Modal(modalEl)
- spyOn(Event.prototype, 'preventDefault').and.callThrough()
+ const spy = spyOn(Event.prototype, 'preventDefault').and.callThrough()
modalEl.addEventListener('shown.bs.modal', () => {
btnClose.click()
})
modalEl.addEventListener('hidden.bs.modal', () => {
- expect(Event.prototype.preventDefault).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
resolve()
})
const modalEl = fixtureEl.querySelector('.modal')
const trigger = fixtureEl.querySelector('[data-bs-toggle="modal"]')
- spyOn(trigger, 'focus')
+ const spy = spyOn(trigger, 'focus')
modalEl.addEventListener('shown.bs.modal', () => {
const modal = Modal.getInstance(modalEl)
const hideListener = () => {
setTimeout(() => {
- expect(trigger.focus).not.toHaveBeenCalled()
+ expect(spy).not.toHaveBeenCalled()
resolve()
}, 20)
}
const modalEl = fixtureEl.querySelector('.modal')
const trigger = fixtureEl.querySelector('[data-bs-toggle="modal"]')
- spyOn(trigger, 'focus')
+ const spy = spyOn(trigger, 'focus')
const showListener = () => {
setTimeout(() => {
- expect(trigger.focus).not.toHaveBeenCalled()
+ expect(spy).not.toHaveBeenCalled()
resolve()
}, 10)
}
jQueryMock.elements = [div]
jQueryMock.fn.modal.call(jQueryMock, { keyboard: false })
- spyOn(Modal.prototype, 'constructor')
- expect(Modal.prototype.constructor).not.toHaveBeenCalledWith(div, { keyboard: false })
+ const spy = spyOn(Modal.prototype, 'constructor')
+ expect(spy).not.toHaveBeenCalledWith(div, { keyboard: false })
const modal = Modal.getInstance(div)
expect(modal).not.toBeNull()
jQueryMock.fn.modal = Modal.jQueryInterface
jQueryMock.elements = [div]
- spyOn(modal, 'show')
+ const spy = spyOn(modal, 'show')
jQueryMock.fn.modal.call(jQueryMock, 'show')
- expect(modal.show).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
})
it('should not call show method', () => {
jQueryMock.fn.modal = Modal.jQueryInterface
jQueryMock.elements = [div]
- spyOn(Modal.prototype, 'show')
+ const spy = spyOn(Modal.prototype, 'show')
jQueryMock.fn.modal.call(jQueryMock)
- expect(Modal.prototype.show).not.toHaveBeenCalled()
+ expect(spy).not.toHaveBeenCalled()
})
})
const closeEl = fixtureEl.querySelector('a')
const offCanvas = new Offcanvas(offCanvasEl)
- spyOn(offCanvas, 'hide')
+ const spy = spyOn(offCanvas, 'hide')
closeEl.click()
expect(offCanvas._config.keyboard).toBeTrue()
- expect(offCanvas.hide).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
})
it('should hide if esc is pressed', () => {
const keyDownEsc = createEvent('keydown')
keyDownEsc.key = 'Escape'
- spyOn(offCanvas, 'hide')
+ const spy = spyOn(offCanvas, 'hide')
offCanvasEl.dispatchEvent(keyDownEsc)
- expect(offCanvas.hide).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
})
it('should hide if esc is pressed and backdrop is static', () => {
const keyDownEsc = createEvent('keydown')
keyDownEsc.key = 'Escape'
- spyOn(offCanvas, 'hide')
+ const spy = spyOn(offCanvas, 'hide')
offCanvasEl.dispatchEvent(keyDownEsc)
- expect(offCanvas.hide).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
})
it('should not hide if esc is not pressed', () => {
const keydownTab = createEvent('keydown')
keydownTab.key = 'Tab'
- spyOn(offCanvas, 'hide')
+ const spy = spyOn(offCanvas, 'hide')
offCanvasEl.dispatchEvent(keydownTab)
- expect(offCanvas.hide).not.toHaveBeenCalled()
+ expect(spy).not.toHaveBeenCalled()
})
it('should not hide if esc is pressed but with keyboard = false', () => {
const keyDownEsc = createEvent('keydown')
keyDownEsc.key = 'Escape'
- spyOn(offCanvas, 'hide')
+ const spy = spyOn(offCanvas, 'hide')
const hidePreventedSpy = jasmine.createSpy('hidePrevented')
offCanvasEl.addEventListener('hidePrevented.bs.offcanvas', hidePreventedSpy)
offCanvasEl.dispatchEvent(keyDownEsc)
expect(hidePreventedSpy).toHaveBeenCalled()
- expect(offCanvas.hide).not.toHaveBeenCalled()
+ expect(spy).not.toHaveBeenCalled()
resolve()
})
const offCanvas = new Offcanvas(offCanvasEl, { backdrop: 'static' })
const clickEvent = new Event('mousedown', { bubbles: true, cancelable: true })
- spyOn(offCanvas._backdrop._config, 'clickCallback').and.callThrough()
- spyOn(offCanvas._backdrop, 'hide').and.callThrough()
+ const spyClick = spyOn(offCanvas._backdrop._config, 'clickCallback').and.callThrough()
+ const spyHide = spyOn(offCanvas._backdrop, 'hide').and.callThrough()
const hidePreventedSpy = jasmine.createSpy('hidePrevented')
offCanvasEl.addEventListener('hidePrevented.bs.offcanvas', hidePreventedSpy)
offCanvasEl.addEventListener('shown.bs.offcanvas', () => {
- expect(offCanvas._backdrop._config.clickCallback).toEqual(jasmine.any(Function))
+ expect(spyClick).toEqual(jasmine.any(Function))
offCanvas._backdrop._getElement().dispatchEvent(clickEvent)
expect(hidePreventedSpy).toHaveBeenCalled()
- expect(offCanvas._backdrop.hide).not.toHaveBeenCalled()
+ expect(spyHide).not.toHaveBeenCalled()
resolve()
})
const offCanvasEl = fixtureEl.querySelector('div')
const offCanvas = new Offcanvas(offCanvasEl)
- spyOn(offCanvas, 'hide').and.callThrough()
+ const spy = spyOn(offCanvas, 'hide').and.callThrough()
offCanvasEl.addEventListener('shown.bs.offcanvas', () => {
const resizeEvent = createEvent('resize')
offCanvasEl.style.removeProperty('position')
window.dispatchEvent(resizeEvent)
- expect(offCanvas.hide).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
resolve()
})
return new Promise(resolve => {
fixtureEl.innerHTML = '<div class="offcanvas"></div>'
- spyOn(ScrollBarHelper.prototype, 'hide').and.callThrough()
- spyOn(ScrollBarHelper.prototype, 'reset').and.callThrough()
+ const spyHide = spyOn(ScrollBarHelper.prototype, 'hide').and.callThrough()
+ const spyReset = spyOn(ScrollBarHelper.prototype, 'reset').and.callThrough()
const offCanvasEl = fixtureEl.querySelector('.offcanvas')
const offCanvas = new Offcanvas(offCanvasEl, { scroll: true })
offCanvasEl.addEventListener('shown.bs.offcanvas', () => {
- expect(ScrollBarHelper.prototype.hide).not.toHaveBeenCalled()
+ expect(spyHide).not.toHaveBeenCalled()
offCanvas.hide()
})
offCanvasEl.addEventListener('hidden.bs.offcanvas', () => {
- expect(ScrollBarHelper.prototype.reset).not.toHaveBeenCalled()
+ expect(spyReset).not.toHaveBeenCalled()
resolve()
})
offCanvas.show()
return new Promise(resolve => {
fixtureEl.innerHTML = '<div class="offcanvas"></div>'
- spyOn(ScrollBarHelper.prototype, 'hide').and.callThrough()
- spyOn(ScrollBarHelper.prototype, 'reset').and.callThrough()
+ const spyHide = spyOn(ScrollBarHelper.prototype, 'hide').and.callThrough()
+ const spyReset = spyOn(ScrollBarHelper.prototype, 'reset').and.callThrough()
const offCanvasEl = fixtureEl.querySelector('.offcanvas')
const offCanvas = new Offcanvas(offCanvasEl, { scroll: false })
offCanvasEl.addEventListener('shown.bs.offcanvas', () => {
- expect(ScrollBarHelper.prototype.hide).toHaveBeenCalled()
+ expect(spyHide).toHaveBeenCalled()
offCanvas.hide()
})
offCanvasEl.addEventListener('hidden.bs.offcanvas', () => {
- expect(ScrollBarHelper.prototype.reset).toHaveBeenCalled()
+ expect(spyReset).toHaveBeenCalled()
resolve()
})
offCanvas.show()
const offCanvas = new Offcanvas(offCanvasEl, { backdrop: true })
const clickEvent = new Event('mousedown', { bubbles: true, cancelable: true })
- spyOn(offCanvas._backdrop._config, 'clickCallback').and.callThrough()
+ const spy = spyOn(offCanvas._backdrop._config, 'clickCallback').and.callThrough()
offCanvasEl.addEventListener('shown.bs.offcanvas', () => {
expect(offCanvas._backdrop._config.clickCallback).toEqual(jasmine.any(Function))
})
offCanvasEl.addEventListener('hidden.bs.offcanvas', () => {
- expect(offCanvas._backdrop._config.clickCallback).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
resolve()
})
scroll: true
})
- spyOn(offCanvas._focustrap, 'activate').and.callThrough()
+ const spy = spyOn(offCanvas._focustrap, 'activate').and.callThrough()
offCanvasEl.addEventListener('shown.bs.offcanvas', () => {
- expect(offCanvas._focustrap.activate).not.toHaveBeenCalled()
+ expect(spy).not.toHaveBeenCalled()
resolve()
})
const offCanvasEl = fixtureEl.querySelector('.offcanvas')
const offCanvas = new Offcanvas(offCanvasEl)
- spyOn(offCanvas, 'show')
+ const spy = spyOn(offCanvas, 'show')
offCanvas.toggle()
- expect(offCanvas.show).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
})
it('should call hide method if show class is present', () => {
offCanvasEl.addEventListener('shown.bs.offcanvas', () => {
expect(offCanvasEl).toHaveClass('show')
- spyOn(offCanvas, 'hide')
+ const spy = spyOn(offCanvas, 'hide')
offCanvas.toggle()
- expect(offCanvas.hide).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
resolve()
})
expect(offCanvasEl).toHaveClass('show')
- spyOn(offCanvas._backdrop, 'show').and.callThrough()
- spyOn(EventHandler, 'trigger').and.callThrough()
+ const spyShow = spyOn(offCanvas._backdrop, 'show').and.callThrough()
+ const spyTrigger = spyOn(EventHandler, 'trigger').and.callThrough()
offCanvas.show()
- expect(EventHandler.trigger).not.toHaveBeenCalled()
- expect(offCanvas._backdrop.show).not.toHaveBeenCalled()
+ expect(spyTrigger).not.toHaveBeenCalled()
+ expect(spyShow).not.toHaveBeenCalled()
})
it('should show a hidden element', () => {
const offCanvasEl = fixtureEl.querySelector('div')
const offCanvas = new Offcanvas(offCanvasEl)
- spyOn(offCanvas._backdrop, 'show').and.callThrough()
+ const spy = spyOn(offCanvas._backdrop, 'show').and.callThrough()
offCanvasEl.addEventListener('shown.bs.offcanvas', () => {
expect(offCanvasEl).toHaveClass('show')
- expect(offCanvas._backdrop.show).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
resolve()
})
const offCanvasEl = fixtureEl.querySelector('div')
const offCanvas = new Offcanvas(offCanvasEl)
- spyOn(offCanvas._backdrop, 'show').and.callThrough()
+ const spy = spyOn(offCanvas._backdrop, 'show').and.callThrough()
const expectEnd = () => {
setTimeout(() => {
- expect(offCanvas._backdrop.show).not.toHaveBeenCalled()
+ expect(spy).not.toHaveBeenCalled()
resolve()
}, 10)
}
fixtureEl.innerHTML = '<div class="offcanvas show"></div>'
const offCanvasEl = fixtureEl.querySelector('div')
- spyOn(Offcanvas.prototype, 'show').and.callThrough()
+ const spy = spyOn(Offcanvas.prototype, 'show').and.callThrough()
offCanvasEl.addEventListener('shown.bs.offcanvas', () => {
resolve()
const instance = Offcanvas.getInstance(offCanvasEl)
expect(instance).not.toBeNull()
- expect(Offcanvas.prototype.show).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
})
})
const offCanvasEl = fixtureEl.querySelector('.offcanvas')
const offCanvas = new Offcanvas(offCanvasEl)
- spyOn(offCanvas._focustrap, 'activate').and.callThrough()
+ const spy = spyOn(offCanvas._focustrap, 'activate').and.callThrough()
offCanvasEl.addEventListener('shown.bs.offcanvas', () => {
- expect(offCanvas._focustrap.activate).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
resolve()
})
it('should do nothing if already shown', () => {
fixtureEl.innerHTML = '<div class="offcanvas"></div>'
- spyOn(EventHandler, 'trigger').and.callThrough()
+ const spyTrigger = spyOn(EventHandler, 'trigger').and.callThrough()
const offCanvasEl = fixtureEl.querySelector('div')
const offCanvas = new Offcanvas(offCanvasEl)
- spyOn(offCanvas._backdrop, 'hide').and.callThrough()
+ const spyHide = spyOn(offCanvas._backdrop, 'hide').and.callThrough()
offCanvas.hide()
- expect(offCanvas._backdrop.hide).not.toHaveBeenCalled()
- expect(EventHandler.trigger).not.toHaveBeenCalled()
+ expect(spyHide).not.toHaveBeenCalled()
+ expect(spyTrigger).not.toHaveBeenCalled()
})
it('should hide a shown element', () => {
const offCanvasEl = fixtureEl.querySelector('div')
const offCanvas = new Offcanvas(offCanvasEl)
- spyOn(offCanvas._backdrop, 'hide').and.callThrough()
+ const spy = spyOn(offCanvas._backdrop, 'hide').and.callThrough()
offCanvas.show()
offCanvasEl.addEventListener('hidden.bs.offcanvas', () => {
expect(offCanvasEl).not.toHaveClass('show')
- expect(offCanvas._backdrop.hide).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
resolve()
})
const offCanvasEl = fixtureEl.querySelector('div')
const offCanvas = new Offcanvas(offCanvasEl)
- spyOn(offCanvas._backdrop, 'hide').and.callThrough()
+ const spy = spyOn(offCanvas._backdrop, 'hide').and.callThrough()
offCanvas.show()
const expectEnd = () => {
setTimeout(() => {
- expect(offCanvas._backdrop.hide).not.toHaveBeenCalled()
+ expect(spy).not.toHaveBeenCalled()
resolve()
}, 10)
}
const offCanvasEl = fixtureEl.querySelector('div')
const offCanvas = new Offcanvas(offCanvasEl)
- spyOn(offCanvas._focustrap, 'deactivate').and.callThrough()
+ const spy = spyOn(offCanvas._focustrap, 'deactivate').and.callThrough()
offCanvas.show()
offCanvasEl.addEventListener('hidden.bs.offcanvas', () => {
- expect(offCanvas._focustrap.deactivate).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
resolve()
})
const offCanvasEl = fixtureEl.querySelector('div')
const offCanvas = new Offcanvas(offCanvasEl)
const backdrop = offCanvas._backdrop
- spyOn(backdrop, 'dispose').and.callThrough()
+ const spyDispose = spyOn(backdrop, 'dispose').and.callThrough()
const focustrap = offCanvas._focustrap
- spyOn(focustrap, 'deactivate').and.callThrough()
+ const spyDeactivate = spyOn(focustrap, 'deactivate').and.callThrough()
expect(Offcanvas.getInstance(offCanvasEl)).toEqual(offCanvas)
- spyOn(EventHandler, 'off')
-
offCanvas.dispose()
- expect(backdrop.dispose).toHaveBeenCalled()
+ expect(spyDispose).toHaveBeenCalled()
expect(offCanvas._backdrop).toBeNull()
- expect(focustrap.deactivate).toHaveBeenCalled()
+ expect(spyDeactivate).toHaveBeenCalled()
expect(offCanvas._focustrap).toBeNull()
expect(Offcanvas.getInstance(offCanvasEl)).toBeNull()
})
const target = fixtureEl.querySelector('a')
- spyOn(Offcanvas.prototype, 'toggle')
+ const spy = spyOn(Offcanvas.prototype, 'toggle')
target.click()
- expect(Offcanvas.prototype.toggle).not.toHaveBeenCalled()
+ expect(spy).not.toHaveBeenCalled()
})
it('should call hide first, if another offcanvas is open', () => {
const trigger = fixtureEl.querySelector('#btn')
const offcanvasEl = fixtureEl.querySelector('#offcanvas')
const offcanvas = new Offcanvas(offcanvasEl)
- spyOn(trigger, 'focus')
+ const spy = spyOn(trigger, 'focus')
offcanvasEl.addEventListener('shown.bs.offcanvas', () => {
offcanvas.hide()
})
offcanvasEl.addEventListener('hidden.bs.offcanvas', () => {
setTimeout(() => {
- expect(trigger.focus).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
resolve()
}, 5)
})
const trigger = fixtureEl.querySelector('#btn')
const offcanvasEl = fixtureEl.querySelector('#offcanvas')
const offcanvas = new Offcanvas(offcanvasEl)
- spyOn(trigger, 'focus')
+ const spy = spyOn(trigger, 'focus')
offcanvasEl.addEventListener('shown.bs.offcanvas', () => {
trigger.style.display = 'none'
offcanvasEl.addEventListener('hidden.bs.offcanvas', () => {
setTimeout(() => {
expect(isVisible(trigger)).toBeFalse()
- expect(trigger.focus).not.toHaveBeenCalled()
+ expect(spy).not.toHaveBeenCalled()
resolve()
}, 5)
})
const div = fixtureEl.querySelector('div')
- spyOn(Offcanvas.prototype, 'show')
+ const spy = spyOn(Offcanvas.prototype, 'show')
jQueryMock.fn.offcanvas = Offcanvas.jQueryInterface
jQueryMock.elements = [div]
jQueryMock.fn.offcanvas.call(jQueryMock, 'show')
- expect(Offcanvas.prototype.show).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
})
it('should create a offcanvas with given config', () => {
const popoverEl = fixtureEl.querySelector('a')
const popover = new Popover(popoverEl, { animation: false })
- spyOn(EventHandler, 'trigger').and.callThrough()
+ const spy = spyOn(EventHandler, 'trigger').and.callThrough()
popover.show()
- expect(EventHandler.trigger).not.toHaveBeenCalledWith(popoverEl, Popover.eventName('show'))
+ expect(spy).not.toHaveBeenCalledWith(popoverEl, Popover.eventName('show'))
expect(document.querySelector('.popover')).toBeNull()
})
jQueryMock.fn.popover = Popover.jQueryInterface
jQueryMock.elements = [popoverEl]
- spyOn(popover, 'show')
+ const spy = spyOn(popover, 'show')
jQueryMock.fn.popover.call(jQueryMock, 'show')
- expect(popover.show).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
})
})
target: 'ss-target'
})
- spyOn(scrollSpy, '_process').and.callThrough()
+ const spy = spyOn(scrollSpy, '_process').and.callThrough()
onScrollStop(() => {
expect(rootEl).toHaveClass('active')
- expect(scrollSpy._process).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
resolve()
}, scrollSpyEl)
target: fixtureEl.querySelector('#ss-target')
})
- spyOn(scrollSpy, '_process').and.callThrough()
+ const spy = spyOn(scrollSpy, '_process').and.callThrough()
onScrollStop(() => {
expect(rootEl).toHaveClass('active')
expect(scrollSpy._activeTarget).toEqual(fixtureEl.querySelector('[href="#detail"]'))
- expect(scrollSpy._process).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
resolve()
}, scrollSpyEl)
const el = fixtureEl.querySelector('.content')
const scrollSpy = new ScrollSpy(el)
- spyOn(scrollSpy._observer, 'disconnect')
+ const spy = spyOn(scrollSpy._observer, 'disconnect')
scrollSpy.refresh()
- expect(scrollSpy._observer.disconnect).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
})
})
jQueryMock.elements = [div]
jQueryMock.fn.scrollspy.call(jQueryMock, { rootMargin: '100px' })
- spyOn(ScrollSpy.prototype, 'constructor')
- expect(ScrollSpy.prototype.constructor).not.toHaveBeenCalledWith(div, { rootMargin: '100px' })
+ const spy = spyOn(ScrollSpy.prototype, 'constructor')
+ expect(spy).not.toHaveBeenCalledWith(div, { rootMargin: '100px' })
const scrollspy = ScrollSpy.getInstance(div)
expect(scrollspy).not.toBeNull()
const div = fixtureEl.querySelector('.content')
const scrollSpy = new ScrollSpy(div)
- spyOn(scrollSpy, 'refresh')
+ const spy = spyOn(scrollSpy, 'refresh')
jQueryMock.fn.scrollspy = ScrollSpy.jQueryInterface
jQueryMock.elements = [div]
jQueryMock.fn.scrollspy.call(jQueryMock, 'refresh')
expect(ScrollSpy.getInstance(div)).toEqual(scrollSpy)
- expect(scrollSpy.refresh).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
})
it('should throw error on undefined method', () => {
const tab = new Tab(tabEl)
const spy = jasmine.createSpy('spy')
- spyOn(tab, '_queueCallback')
+ const spyQueue = spyOn(tab, '_queueCallback')
tab._activate(null, spy)
- expect(tab._queueCallback).not.toHaveBeenCalled()
+ expect(spyQueue).not.toHaveBeenCalled()
expect(spy).not.toHaveBeenCalled()
})
})
const keydown = createEvent('keydown')
keydown.key = 'Enter'
- spyOn(Event.prototype, 'stopPropagation').and.callThrough()
- spyOn(Event.prototype, 'preventDefault').and.callThrough()
- spyOn(tab, '_keydown')
- spyOn(tab, '_getChildren')
+ const spyStop = spyOn(Event.prototype, 'stopPropagation').and.callThrough()
+ const spyPrevent = spyOn(Event.prototype, 'preventDefault').and.callThrough()
+ const spyKeydown = spyOn(tab, '_keydown')
+ const spyGet = spyOn(tab, '_getChildren')
tabEl.dispatchEvent(keydown)
- expect(tab._keydown).toHaveBeenCalled()
- expect(tab._getChildren).not.toHaveBeenCalled()
+ expect(spyKeydown).toHaveBeenCalled()
+ expect(spyGet).not.toHaveBeenCalled()
- expect(Event.prototype.stopPropagation).not.toHaveBeenCalled()
- expect(Event.prototype.preventDefault).not.toHaveBeenCalled()
+ expect(spyStop).not.toHaveBeenCalled()
+ expect(spyPrevent).not.toHaveBeenCalled()
})
it('if keydown event is right/down arrow, handle it', () => {
const tabEl2 = fixtureEl.querySelector('#tab2')
const tab = new Tab(tabEl)
const tab2 = new Tab(tabEl2)
- spyOn(tab, 'show').and.callThrough()
- spyOn(tab2, 'show').and.callThrough()
+ const spyShow1 = spyOn(tab, 'show').and.callThrough()
+ const spyShow2 = spyOn(tab2, 'show').and.callThrough()
- spyOn(Event.prototype, 'stopPropagation').and.callThrough()
- spyOn(Event.prototype, 'preventDefault').and.callThrough()
+ const spyStop = spyOn(Event.prototype, 'stopPropagation').and.callThrough()
+ const spyPrevent = spyOn(Event.prototype, 'preventDefault').and.callThrough()
let keydown = createEvent('keydown')
keydown.key = 'ArrowRight'
tabEl.dispatchEvent(keydown)
- expect(tab2.show).toHaveBeenCalled()
+ expect(spyShow2).toHaveBeenCalled()
keydown = createEvent('keydown')
keydown.key = 'ArrowDown'
tabEl2.dispatchEvent(keydown)
- expect(tab.show).toHaveBeenCalled()
+ expect(spyShow1).toHaveBeenCalled()
- expect(Event.prototype.stopPropagation).toHaveBeenCalledTimes(2)
- expect(Event.prototype.preventDefault).toHaveBeenCalledTimes(2)
+ expect(spyStop).toHaveBeenCalledTimes(2)
+ expect(spyPrevent).toHaveBeenCalledTimes(2)
})
it('if keydown event is left arrow, handle it', () => {
const tabEl2 = fixtureEl.querySelector('#tab2')
const tab = new Tab(tabEl)
const tab2 = new Tab(tabEl2)
- spyOn(tab, 'show').and.callThrough()
- spyOn(tab2, 'show').and.callThrough()
+ const spyShow1 = spyOn(tab, 'show').and.callThrough()
+ const spyShow2 = spyOn(tab2, 'show').and.callThrough()
- spyOn(Event.prototype, 'stopPropagation').and.callThrough()
- spyOn(Event.prototype, 'preventDefault').and.callThrough()
+ const spyStop = spyOn(Event.prototype, 'stopPropagation').and.callThrough()
+ const spyPrevent = spyOn(Event.prototype, 'preventDefault').and.callThrough()
let keydown = createEvent('keydown')
keydown.key = 'ArrowLeft'
tabEl2.dispatchEvent(keydown)
- expect(tab.show).toHaveBeenCalled()
+ expect(spyShow1).toHaveBeenCalled()
keydown = createEvent('keydown')
keydown.key = 'ArrowUp'
tabEl.dispatchEvent(keydown)
- expect(tab2.show).toHaveBeenCalled()
+ expect(spyShow2).toHaveBeenCalled()
- expect(Event.prototype.stopPropagation).toHaveBeenCalledTimes(2)
- expect(Event.prototype.preventDefault).toHaveBeenCalledTimes(2)
+ expect(spyStop).toHaveBeenCalledTimes(2)
+ expect(spyPrevent).toHaveBeenCalledTimes(2)
})
it('if keydown event is right arrow and next element is disabled', () => {
const tab2 = new Tab(tabEl2)
const tab3 = new Tab(tabEl3)
const tab4 = new Tab(tabEl4)
- spyOn(tab, 'show').and.callThrough()
- spyOn(tab2, 'show').and.callThrough()
- spyOn(tab3, 'show').and.callThrough()
- spyOn(tab4, 'show').and.callThrough()
+ const spy1 = spyOn(tab, 'show').and.callThrough()
+ const spy2 = spyOn(tab2, 'show').and.callThrough()
+ const spy3 = spyOn(tab3, 'show').and.callThrough()
+ const spy4 = spyOn(tab4, 'show').and.callThrough()
const keydown = createEvent('keydown')
keydown.key = 'ArrowRight'
tabEl.dispatchEvent(keydown)
- expect(tab.show).not.toHaveBeenCalled()
- expect(tab2.show).not.toHaveBeenCalled()
- expect(tab3.show).not.toHaveBeenCalled()
- expect(tab4.show).toHaveBeenCalledTimes(1)
+ expect(spy1).not.toHaveBeenCalled()
+ expect(spy2).not.toHaveBeenCalled()
+ expect(spy3).not.toHaveBeenCalled()
+ expect(spy4).toHaveBeenCalledTimes(1)
})
it('if keydown event is left arrow and next element is disabled', () => {
const tab2 = new Tab(tabEl2)
const tab3 = new Tab(tabEl3)
const tab4 = new Tab(tabEl4)
- spyOn(tab, 'show').and.callThrough()
- spyOn(tab2, 'show').and.callThrough()
- spyOn(tab3, 'show').and.callThrough()
- spyOn(tab4, 'show').and.callThrough()
+ const spy1 = spyOn(tab, 'show').and.callThrough()
+ const spy2 = spyOn(tab2, 'show').and.callThrough()
+ const spy3 = spyOn(tab3, 'show').and.callThrough()
+ const spy4 = spyOn(tab4, 'show').and.callThrough()
const keydown = createEvent('keydown')
keydown.key = 'ArrowLeft'
tabEl4.dispatchEvent(keydown)
- expect(tab4.show).not.toHaveBeenCalled()
- expect(tab3.show).not.toHaveBeenCalled()
- expect(tab2.show).not.toHaveBeenCalled()
- expect(tab.show).toHaveBeenCalledTimes(1)
+ expect(spy4).not.toHaveBeenCalled()
+ expect(spy3).not.toHaveBeenCalled()
+ expect(spy2).not.toHaveBeenCalled()
+ expect(spy1).toHaveBeenCalledTimes(1)
})
})
const div = fixtureEl.querySelector('.nav > div')
const tab = new Tab(div)
- spyOn(tab, 'show')
+ const spy = spyOn(tab, 'show')
jQueryMock.fn.tab = Tab.jQueryInterface
jQueryMock.elements = [div]
jQueryMock.fn.tab.call(jQueryMock, 'show')
expect(Tab.getInstance(div)).toEqual(tab)
- expect(tab.show).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
})
it('should throw error on undefined method', () => {
].join('')
const tabEl = fixtureEl.querySelector('[href="#test2"]')
- spyOn(Event.prototype, 'preventDefault').and.callThrough()
+ const spy = spyOn(Event.prototype, 'preventDefault').and.callThrough()
tabEl.addEventListener('shown.bs.tab', () => {
expect(tabEl).toHaveClass('active')
- expect(Event.prototype.preventDefault).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
resolve()
})
setTimeout(() => {
toast._config.autohide = false
toastEl.addEventListener('shown.bs.toast', () => {
- expect(toast._clearTimeout).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
expect(toast._timeout).toBeNull()
resolve()
})
toast.show()
}, toast._config.delay / 2)
- spyOn(toast, '_clearTimeout').and.callThrough()
+ const spy = spyOn(toast, '_clearTimeout').and.callThrough()
toast.show()
})
const toastEl = fixtureEl.querySelector('div')
const toast = new Toast(toastEl)
- spyOn(toastEl.classList, 'contains')
+ const spy = spyOn(toastEl.classList, 'contains')
toast.hide()
- expect(toastEl.classList.contains).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
})
it('should not trigger hidden if hide is prevented', () => {
const div = fixtureEl.querySelector('div')
const toast = new Toast(div)
- spyOn(toast, 'show')
+ const spy = spyOn(toast, 'show')
jQueryMock.fn.toast = Toast.jQueryInterface
jQueryMock.elements = [div]
jQueryMock.fn.toast.call(jQueryMock, 'show')
expect(Toast.getInstance(div)).toEqual(toast)
- expect(toast.show).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
})
it('should throw error on undefined method', () => {
trigger: 'click'
})
- spyOn(tooltip, 'toggle').and.callThrough()
+ const spy = spyOn(tooltip, 'toggle').and.callThrough()
tooltipEl.addEventListener('shown.bs.tooltip', () => {
- expect(tooltip.toggle).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
resolve()
})
trigger: 'click'
})
- spyOn(tooltip, 'toggle').and.callThrough()
+ const spy = spyOn(tooltip, 'toggle').and.callThrough()
tooltipEl.addEventListener('shown.bs.tooltip', () => {
tooltipEl.click()
})
tooltipEl.addEventListener('hidden.bs.tooltip', () => {
- expect(tooltip.toggle).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
resolve()
})
const tooltipEl = fixtureEl.querySelector('a')
const tooltip = new Tooltip(tooltipEl)
- spyOn(tooltip, 'show')
+ const spy = spyOn(tooltip, 'show')
tooltipEl.querySelector('rect').dispatchEvent(createEvent('mouseover', { bubbles: true }))
setTimeout(() => {
- expect(tooltip.show).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
resolve()
}, 0)
})
const tooltip = new Tooltip(tooltipEl)
document.documentElement.ontouchstart = noop
- spyOn(EventHandler, 'on').and.callThrough()
+ const spy = spyOn(EventHandler, 'on').and.callThrough()
tooltipEl.addEventListener('shown.bs.tooltip', () => {
expect(document.querySelector('.tooltip')).not.toBeNull()
- expect(EventHandler.on).toHaveBeenCalledWith(jasmine.any(Object), 'mouseover', noop)
+ expect(spy).toHaveBeenCalledWith(jasmine.any(Object), 'mouseover', noop)
document.documentElement.ontouchstart = undefined
resolve()
})
delay: 150
})
- spyOn(tooltip, 'show')
+ const spy = spyOn(tooltip, 'show')
setTimeout(() => {
- expect(tooltip.show).not.toHaveBeenCalled()
+ expect(spy).not.toHaveBeenCalled()
}, 100)
setTimeout(() => {
- expect(tooltip.show).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
resolve()
}, 200)
delay: 150
})
- spyOn(tooltip, 'show')
+ const spy = spyOn(tooltip, 'show')
setTimeout(() => {
- expect(tooltip.show).not.toHaveBeenCalled()
+ expect(spy).not.toHaveBeenCalled()
tooltipEl.dispatchEvent(createEvent('mouseover'))
}, 100)
setTimeout(() => {
- expect(tooltip.show).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
expect(document.querySelectorAll('.tooltip')).toHaveSize(0)
resolve()
}, 200)
const tooltip = new Tooltip(tooltipEl)
const triggerChild = tooltipEl.querySelector('b')
- spyOn(tooltip, 'hide').and.callThrough()
+ const spy = spyOn(tooltip, 'hide').and.callThrough()
tooltipEl.addEventListener('mouseover', () => {
const moveMouseToChildEvent = createEvent('mouseout')
})
tooltipEl.addEventListener('mouseout', () => {
- expect(tooltip.hide).not.toHaveBeenCalled()
+ expect(spy).not.toHaveBeenCalled()
resolve()
})
const tooltipEl = fixtureEl.querySelector('a')
const tooltip = new Tooltip(tooltipEl)
+ const spy = spyOn(EventHandler, 'off')
tooltipEl.addEventListener('shown.bs.tooltip', () => {
document.documentElement.ontouchstart = noop
- spyOn(EventHandler, 'off')
tooltip.hide()
})
tooltipEl.addEventListener('hidden.bs.tooltip', () => {
expect(document.querySelector('.tooltip')).toBeNull()
- expect(EventHandler.off).toHaveBeenCalledWith(jasmine.any(Object), 'mouseover', noop)
+ expect(spy).toHaveBeenCalledWith(jasmine.any(Object), 'mouseover', noop)
document.documentElement.ontouchstart = undefined
resolve()
})
const tooltip = new Tooltip(tooltipEl)
tooltipEl.addEventListener('shown.bs.tooltip', () => {
- spyOn(tooltip._popper, 'update')
+ const spy = spyOn(tooltip._popper, 'update')
tooltip.update()
- expect(tooltip._popper.update).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
resolve()
})
const tooltipEl = fixtureEl.querySelector('a')
const tooltip = new Tooltip(tooltipEl)
- spyOn(document, 'createElement').and.callThrough()
+ const spy = spyOn(document, 'createElement').and.callThrough()
expect(tooltip._getTipElement()).toBeDefined()
- expect(document.createElement).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
})
it('should return the created tip element', () => {
const div = fixtureEl.querySelector('div')
const tooltip = new Tooltip(div)
- spyOn(tooltip, 'show')
+ const spy = spyOn(tooltip, 'show')
jQueryMock.fn.tooltip = Tooltip.jQueryInterface
jQueryMock.elements = [div]
jQueryMock.fn.tooltip.call(jQueryMock, 'show')
expect(Tooltip.getInstance(div)).toEqual(tooltip)
- expect(tooltip.show).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
})
it('should throw error on undefined method', () => {
'</div>'
].join('')
- spyOn(DummyClass2, 'getOrCreateInstance').and.callThrough()
- spyOn(DummyClass2.prototype, 'testMethod')
+ const spyGet = spyOn(DummyClass2, 'getOrCreateInstance').and.callThrough()
+ const spyTest = spyOn(DummyClass2.prototype, 'testMethod')
const componentWrapper = fixtureEl.querySelector('#foo')
const btnClose = fixtureEl.querySelector('[data-bs-dismiss="test"]')
const event = createEvent('click')
enableDismissTrigger(DummyClass2, 'testMethod')
btnClose.dispatchEvent(event)
- expect(DummyClass2.getOrCreateInstance).toHaveBeenCalledWith(componentWrapper)
- expect(DummyClass2.prototype.testMethod).toHaveBeenCalled()
+ expect(spyGet).toHaveBeenCalledWith(componentWrapper)
+ expect(spyTest).toHaveBeenCalled()
})
it('if data-bs-dismiss="PluginName" hasn\'t got "data-bs-target", "getOrCreateInstance" has to be initialized by closest "plugin.Name" class', () => {
'</div>'
].join('')
- spyOn(DummyClass2, 'getOrCreateInstance').and.callThrough()
- spyOn(DummyClass2.prototype, 'hide')
+ const spyGet = spyOn(DummyClass2, 'getOrCreateInstance').and.callThrough()
+ const spyHide = spyOn(DummyClass2.prototype, 'hide')
const componentWrapper = fixtureEl.querySelector('#foo')
const btnClose = fixtureEl.querySelector('[data-bs-dismiss="test"]')
const event = createEvent('click')
enableDismissTrigger(DummyClass2)
btnClose.dispatchEvent(event)
- expect(DummyClass2.getOrCreateInstance).toHaveBeenCalledWith(componentWrapper)
- expect(DummyClass2.prototype.hide).toHaveBeenCalled()
+ expect(spyGet).toHaveBeenCalledWith(componentWrapper)
+ expect(spyHide).toHaveBeenCalled()
})
it('if data-bs-dismiss="PluginName" is disabled, must not trigger function', () => {
'</div>'
].join('')
- spyOn(DummyClass2, 'getOrCreateInstance').and.callThrough()
+ const spy = spyOn(DummyClass2, 'getOrCreateInstance').and.callThrough()
const btnClose = fixtureEl.querySelector('[data-bs-dismiss="test"]')
const event = createEvent('click')
enableDismissTrigger(DummyClass2)
btnClose.dispatchEvent(event)
- expect(DummyClass2.getOrCreateInstance).not.toHaveBeenCalled()
+ expect(spy).not.toHaveBeenCalled()
})
it('should prevent default when the trigger is <a> or <area>', () => {
const event = createEvent('click')
enableDismissTrigger(DummyClass2)
- spyOn(Event.prototype, 'preventDefault').and.callThrough()
+ const spy = spyOn(Event.prototype, 'preventDefault').and.callThrough()
btnClose.dispatchEvent(event)
- expect(Event.prototype.preventDefault).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
})
})
})
const trapElement = fixtureEl.querySelector('div')
- spyOn(trapElement, 'focus')
+ const spy = spyOn(trapElement, 'focus')
const focustrap = new FocusTrap({ trapElement })
focustrap.activate()
- expect(trapElement.focus).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
})
it('if configured not to autofocus, should not autofocus itself', () => {
const trapElement = fixtureEl.querySelector('div')
- spyOn(trapElement, 'focus')
+ const spy = spyOn(trapElement, 'focus')
const focustrap = new FocusTrap({ trapElement, autofocus: false })
focustrap.activate()
- expect(trapElement.focus).not.toHaveBeenCalled()
+ expect(spy).not.toHaveBeenCalled()
})
it('should force focus inside focus trap if it can', () => {
const inside = document.getElementById('inside')
const focusInListener = () => {
- expect(inside.focus).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
document.removeEventListener('focusin', focusInListener)
resolve()
}
- spyOn(inside, 'focus')
+ const spy = spyOn(inside, 'focus')
spyOn(SelectorEngine, 'focusableChildren').and.callFake(() => [inside])
document.addEventListener('focusin', focusInListener)
const outside = document.getElementById('outside')
spyOn(SelectorEngine, 'focusableChildren').and.callFake(() => [first, inside, last])
- spyOn(first, 'focus').and.callThrough()
+ const spy = spyOn(first, 'focus').and.callThrough()
const focusInListener = () => {
- expect(first.focus).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
first.removeEventListener('focusin', focusInListener)
resolve()
}
const outside = document.getElementById('outside')
spyOn(SelectorEngine, 'focusableChildren').and.callFake(() => [first, inside, last])
- spyOn(last, 'focus').and.callThrough()
+ const spy = spyOn(last, 'focus').and.callThrough()
const focusInListener = () => {
- expect(last.focus).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
last.removeEventListener('focusin', focusInListener)
resolve()
}
focustrap.activate()
const focusInListener = () => {
- expect(focustrap._config.trapElement.focus).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
document.removeEventListener('focusin', focusInListener)
resolve()
}
- spyOn(focustrap._config.trapElement, 'focus')
+ const spy = spyOn(focustrap._config.trapElement, 'focus')
document.addEventListener('focusin', focusInListener)
const focustrap = new FocusTrap({ trapElement: fixtureEl })
focustrap.activate()
- spyOn(EventHandler, 'off')
+ const spy = spyOn(EventHandler, 'off')
focustrap.deactivate()
- expect(EventHandler.off).toHaveBeenCalled()
+ expect(spy).toHaveBeenCalled()
})
it('doesn\'t try removing event listeners unless it needs to (in case it hasn\'t been activated)', () => {
const focustrap = new FocusTrap({ trapElement: fixtureEl })
- spyOn(EventHandler, 'off')
+ const spy = spyOn(EventHandler, 'off')
focustrap.deactivate()
- expect(EventHandler.off).not.toHaveBeenCalled()
+ expect(spy).not.toHaveBeenCalled()
})
})
})
const spy = jasmine.createSpy()
const spy2 = jasmine.createSpy()
- spyOn(document, 'addEventListener').and.callThrough()
+ const spyAdd = spyOn(document, 'addEventListener').and.callThrough()
spyOnProperty(document, 'readyState').and.returnValue('loading')
Util.onDOMContentLoaded(spy)
expect(spy).toHaveBeenCalled()
expect(spy2).toHaveBeenCalled()
- expect(document.addEventListener).toHaveBeenCalledTimes(1)
+ expect(spyAdd).toHaveBeenCalledTimes(1)
})
it('should execute callback if readyState is not "loading"', () => {
return htmlUnsafe
}
- spyOn(DOMParser.prototype, 'parseFromString')
+ const spy = spyOn(DOMParser.prototype, 'parseFromString')
const result = sanitizeHtml(template, DefaultAllowlist, mySanitize)
expect(result).toEqual(template)
- expect(DOMParser.prototype.parseFromString).not.toHaveBeenCalled()
+ expect(spy).not.toHaveBeenCalled()
})
it('should allow multiple sanitation passes of the same template', () => {
deleteDocumentElementOntouchstart()
const swipe = new Swipe(swipeEl)
- spyOn(swipe, '_handleSwipe')
+ const spy = spyOn(swipe, '_handleSwipe')
mockSwipeGesture(swipeEl, {
pos: [300, 10],
})
restorePointerEvents()
- expect(swipe._handleSwipe).not.toHaveBeenCalled()
+ expect(spy).not.toHaveBeenCalled()
})
it('should allow swipeRight and call "rightCallback" with pointer events', () => {