From 6f5b32235af9cb400858fa110f585121e73f425a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Thu, 13 Jun 2024 14:50:44 +0800 Subject: [PATCH] test: fix test case --- tests/scrollWidth.test.tsx | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/tests/scrollWidth.test.tsx b/tests/scrollWidth.test.tsx index 5757b89..b1f8fd1 100644 --- a/tests/scrollWidth.test.tsx +++ b/tests/scrollWidth.test.tsx @@ -17,20 +17,35 @@ describe('List.scrollWidth', () => { let mockMouseEvent; let pageX: number; + const holderHeight = 100; let holderWidth = 100; beforeAll(() => { mockElement = spyElementPrototypes(HTMLElement, { offsetHeight: { - get: () => ITEM_HEIGHT, + get() { + if (this.classList.contains('rc-virtual-list-holder')) { + return holderHeight; + } + return ITEM_HEIGHT; + }, + }, + offsetWidth: { + get() { + return holderWidth; + }, }, clientHeight: { - get: () => holderWidth, + get() { + return holderWidth; + }, + }, + getBoundingClientRect() { + return { + width: holderWidth, + height: holderHeight, + }; }, - getBoundingClientRect: () => ({ - width: holderWidth, - height: 100, - }), }); mockMouseEvent = spyElementPrototypes(MouseEvent, {