Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('observe without MutationObserver', () => {
const bs = createBS()
const obDom = new ObserveDom(bs)
jest.advanceTimersByTime(1000)
expect(bs.refresh).not.toBeCalled()
mockDomOffset(bs.scroller.content, {
width: 400
})
jest.advanceTimersByTime(1000)
expect(bs.refresh).toBeCalledTimes(1)
// destroy
bs.hooks.trigger('destroy')
mockDomOffset(bs.scroller.content, {
width: 500
})
jest.advanceTimersByTime(1000)
expect(bs.refresh).toBeCalledTimes(1)
})
beforeAll(() => {
// create DOM
const wrapper = document.createElement('div')
const content = document.createElement('div')
wrapper.appendChild(content)
// mock bscroll
bscroll = new BScroll(wrapper, {})
bscroll.maxScrollY = MAX_SCROLL_Y
bscroll.movingDirectionY = MOVING_DIRECTION_Y
})
beforeAll(() => {
// create Dom
const wrapper = document.createElement('div')
const content = document.createElement('div')
wrapper.appendChild(content)
// mock bscroll
options = {
scrollbar: CONFIG_SCROLL_BAR,
scrollX: true,
scrollY: true
}
bscroll = new BScroll(wrapper, options)
})
beforeEach(() => {
// create Dom indicator
const indicatorWrapper = document.createElement('div')
const indicatorEl = document.createElement('div')
indicatorWrapper.appendChild(indicatorEl)
// mock clientHeight and clientWidth
mockDomClient(indicatorWrapper, { height: 100, width: 100 })
indicatorOptions = {
wrapper: indicatorWrapper,
direction: 'vertical' as Direction,
fade: true,
interactive: true
}
})
registorEvent() {
this.eventRegistor = new EventRegister(this.scroll.scroller.wrapper, [
{
name: 'wheel',
handler: this.wheelHandler.bind(this)
},
{
name: 'mousewheel',
handler: this.wheelHandler.bind(this)
},
{
name: 'DOMMouseScroll', // FireFox
handler: this.wheelHandler.bind(this)
}
])
}
wheelHandler(e: CompatibleWheelEvent) {
it("should make childScroll'options.click false when both BScroll' options.click are true", () => {
const parentScroll = new BScroll(parentWrapper, {
click: true
})
const childScroll = new BScroll(childWrapper, {
click: true
})
let nestedScroll1 = new NestedScroll(parentScroll)
let nestedScroll2 = new NestedScroll(childScroll)
expect(childScroll.options.click).toBe(false)
})
})
it('should invoice move method when dispatch touchmove', () => {
actionsHandler = new ActionsHandler(wrapper, options)
const moveMockHandler = jest.fn().mockImplementation(() => {
return 'dummy test'
})
actionsHandler.hooks.on('move', moveMockHandler)
dispatchMouse(wrapper, 'mousedown')
dispatchMouse(window, 'mousemove')
expect(moveMockHandler).toBeCalled()
})
it('should invoice end method when dispatch touchend', () => {
actionsHandler = new ActionsHandler(wrapper, options)
const endMockHandler = jest.fn().mockImplementation(() => {
return 'dummy test'
})
actionsHandler.hooks.on('end', endMockHandler)
dispatchMouse(wrapper, 'mousedown')
dispatchMouse(window, 'mouseup')
expect(endMockHandler).toBeCalled()
})