diff --git a/src/List.tsx b/src/List.tsx index d9fb278..f56cd47 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 415bc87..fa62a6a 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', ); });