From 0aded7cdde8d311ba486c23fcd53a6ca71c301ae Mon Sep 17 00:00:00 2001 From: shutao Date: Wed, 21 Aug 2024 16:16:25 +0800 Subject: [PATCH] =?UTF-8?q?update=20scroll-view.test.js=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9Escrollevent=E6=B5=8B=E8=AF=95=E4=BE=8B=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/component/scroll-view/scroll-view.test.js | 8 ++++++++ pages/component/scroll-view/scroll-view.uvue | 9 ++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/pages/component/scroll-view/scroll-view.test.js b/pages/component/scroll-view/scroll-view.test.js index 09d8bce5..106e2eb6 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 7e8ffc09..8553c60a 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) + } + } }, } -- GitLab