diff --git a/pages/component/scroll-view/scroll-view.test.js b/pages/component/scroll-view/scroll-view.test.js index 09d8bce58ec23c92828054814018edbfd3541846..106e2eb6a81d757fa504955afca54bf624aae645 100644 --- a/pages/component/scroll-view/scroll-view.test.js +++ b/pages/component/scroll-view/scroll-view.test.js @@ -78,4 +78,12 @@ describe('component-native-scroll-view', () => { expect(endDetail.scrollWidth).toBeGreaterThan(0) }) } + + it('通过UniElement.scrollBy检测scroll事件是否触发',async()=>{ + await page.callMethod('setVerticalScrollBy', 120) + // await page.waitFor(600) + const scrollDetail = await page.data('scrollDetailTest') + console.log('setVerticalScrollBy scrollDetail:', scrollDetail) + expect(scrollDetail.scrollTop).toBe(120) + }) }); diff --git a/pages/component/scroll-view/scroll-view.uvue b/pages/component/scroll-view/scroll-view.uvue index 7e8ffc096396fdd34142517d2f40066c0de2f1eb..8553c60aded0922afb09f254d15ff25bba5bc159 100644 --- a/pages/component/scroll-view/scroll-view.uvue +++ b/pages/component/scroll-view/scroll-view.uvue @@ -11,7 +11,7 @@ + @scrolltoupper="upper" @scrolltolower="lower" @scroll="scroll" @scrollend="end" :show-scrollbar="showScrollbar" id="verticalScrollView"> A B C @@ -150,6 +150,13 @@ break; } }, + // 自动化测试专用 + setVerticalScrollBy(y: number) { + const element = uni.getElementById("verticalScrollView") + if(element != null) { + element.scrollBy(0, y) + } + } }, }