Skip to content

Commit 717e1b5

Browse files
committed
chore: Update mock to dedup List component in jest
1 parent 84bb3af commit 717e1b5

File tree

3 files changed

+6
-16
lines changed

3 files changed

+6
-16
lines changed

src/List.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export interface ListProps<T> extends React.HTMLAttributes<any> {
4747
onScroll?: React.UIEventHandler<HTMLElement>;
4848
}
4949

50-
function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
50+
export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
5151
const {
5252
prefixCls,
5353
className,

src/mock.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import * as React from 'react';
2-
import OriginList, { ListProps, ListRef } from './List';
2+
import { RawList, ListProps, ListRef } from './List';
33

4-
const List = React.forwardRef((props: ListProps<any>, ref: React.Ref<ListRef>) => (
5-
<OriginList {...props} ref={ref} virtual={false} />
6-
)) as <Item = any>(
4+
const List = React.forwardRef((props: ListProps<any>, ref: React.Ref<ListRef>) =>
5+
RawList({ ...props, virtual: false }, ref),
6+
) as <Item = any>(
77
props: React.PropsWithChildren<ListProps<Item>> & { ref?: React.Ref<ListRef> },
88
) => React.ReactElement;
99

tests/mock.test.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,7 @@ describe('MockList', () => {
2121
.key(),
2222
).toBe(String(i));
2323
}
24-
});
25-
26-
it('do not trigger `onSkipRender`', () => {
27-
const onSkipRender = jest.fn();
28-
const wrapper = mount(
29-
<MockList data={[0]} itemKey={id => id}>
30-
{id => <span>{id}</span>}
31-
</MockList>,
32-
);
3324

34-
wrapper.setProps({ data: [0, 1] });
35-
expect(onSkipRender).not.toHaveBeenCalled();
25+
expect(wrapper.find('List')).toHaveLength(1);
3626
});
3727
});

0 commit comments

Comments
 (0)