From 78ad219c42911cc1147863f6312e5f6d95aaca96 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: Fri, 20 Sep 2024 19:53:09 +0800 Subject: [PATCH] chore: not add attr --- src/List.tsx | 4 ---- tests/scroll.test.js | 30 ++++++++++++++++++++++++------ tests/touch.test.js | 30 ++++++++++++++++++++++-------- 3 files changed, 46 insertions(+), 18 deletions(-) diff --git a/src/List.tsx b/src/List.tsx index d9fb2786..f56cd47e 100644 --- a/src/List.tsx +++ b/src/List.tsx @@ -561,10 +561,6 @@ export function RawList(props: ListProps, ref: React.Ref) { containerProps.dir = 'rtl'; } - if (process.env.NODE_ENV !== 'production') { - containerProps['data-dev-offset-top'] = offsetTop; - } - return (
({ id: String(index) })); } +// Mock ScrollBar +jest.mock('../src/ScrollBar', () => { + const OriScrollBar = jest.requireActual('../src/ScrollBar').default; + const React = jest.requireActual('react'); + return React.forwardRef((props, ref) => { + const { scrollOffset } = props; + + return ( +
+ +
+ ); + }); +}); + describe('List.Scroll', () => { let mockElement; let boundingRect = { @@ -525,13 +540,16 @@ describe('List.Scroll', () => { await Promise.resolve(); }); - expect(container.querySelectorAll('[data-dev-offset-top]')[0]).toHaveAttribute( - 'data-dev-offset-top', - '0', - ); - expect(container.querySelectorAll('[data-dev-offset-top]')[1]).toHaveAttribute( - 'data-dev-offset-top', + // inner + expect(container.querySelectorAll('[data-dev-offset]')[0]).toHaveAttribute( + 'data-dev-offset', '10', ); + + // outer + expect(container.querySelectorAll('[data-dev-offset]')[1]).toHaveAttribute( + 'data-dev-offset', + '0', + ); }); }); diff --git a/tests/touch.test.js b/tests/touch.test.js index 415bc87c..fa62a6a2 100644 --- a/tests/touch.test.js +++ b/tests/touch.test.js @@ -4,6 +4,21 @@ import React from 'react'; import List from '../src'; import { spyElementPrototypes } from './utils/domHook'; +// Mock ScrollBar +jest.mock('../src/ScrollBar', () => { + const OriScrollBar = jest.requireActual('../src/ScrollBar').default; + const React = jest.requireActual('react'); + return React.forwardRef((props, ref) => { + const { scrollOffset } = props; + + return ( +
+ +
+ ); + }); +}); + function genData(count) { return new Array(count).fill(null).map((_, index) => ({ id: String(index) })); } @@ -161,17 +176,16 @@ describe('List.Touch', () => { await Promise.resolve(); }); - expect(container.querySelectorAll('[data-dev-offset-top]')[0]).toHaveAttribute( - 'data-dev-offset-top', + // inner not to be 0 + expect(container.querySelectorAll('[data-dev-offset]')[0]).toHaveAttribute('data-dev-offset'); + expect(container.querySelectorAll('[data-dev-offset]')[0]).not.toHaveAttribute( + 'data-dev-offset', '0', ); - // inner not to be 0 - expect(container.querySelectorAll('[data-dev-offset-top]')[1]).toHaveAttribute( - 'data-dev-offset-top', - ); - expect(container.querySelectorAll('[data-dev-offset-top]')[1]).not.toHaveAttribute( - 'data-dev-offset-top', + // outer + expect(container.querySelectorAll('[data-dev-offset]')[1]).toHaveAttribute( + 'data-dev-offset', '0', ); });