From 8a531c7d5568e1bacd09b4dd16ef078c5bd84134 Mon Sep 17 00:00:00 2001
From: HaixingOoO <974758671@qq.com>
Date: Wed, 12 Feb 2025 22:42:26 +0800
Subject: [PATCH] test(list): fix test snap
---
src/list/List.tsx | 46 ++++++++++-------------
test/snap/__snapshots__/csr.test.jsx.snap | 26 +------------
test/snap/__snapshots__/ssr.test.jsx.snap | 2 +-
3 files changed, 22 insertions(+), 52 deletions(-)
diff --git a/src/list/List.tsx b/src/list/List.tsx
index 0571d84308..dfa24a9b18 100644
--- a/src/list/List.tsx
+++ b/src/list/List.tsx
@@ -52,9 +52,10 @@ const List = forwardRefWithStatics(
const [local, t] = useLocaleReceiver('list');
const listItems = useMemo(
- () => React.Children.map(children, (child: React.ReactElement) => child.props),
+ () => React.Children.map(children, (child: React.ReactElement) => child.props) ?? [],
[children],
);
+
const { virtualConfig, cursorStyle, listStyle, isVirtualScroll, onInnerVirtualScroll, scrollToElement } =
useListVirtualScroll(scroll, wrapperRef, listItems);
@@ -98,29 +99,22 @@ const List = forwardRefWithStatics(
scrollTo: scrollToElement,
}));
- const renderContent = () => {
- const propsHeaderContent = parseTNode(header);
- const propsFooterContent = parseTNode(footer);
-
- return (
- <>
- {propsHeaderContent ?
{propsHeaderContent}
: null}
- {isVirtualScroll ? (
- <>
-
-
- {virtualConfig.visibleData.map((item, index) => (
-
- ))}
-
- >
- ) : (
-
- )}
- {propsFooterContent ? {propsFooterContent}
: null}
- >
- );
- };
+ const renderContent = () => (
+ <>
+ {isVirtualScroll ? (
+ <>
+
+
+ {virtualConfig.visibleData.map((item, index) => (
+
+ ))}
+
+ >
+ ) : (
+
+ )}
+ >
+ );
return (
- {header &&
{header}
}
+ {header &&
{parseTNode(header)}
}
{renderContent()}
{asyncLoading && loadElement}
- {footer &&
{footer}
}
+ {footer &&
{parseTNode(footer)}
}
);
},
diff --git a/test/snap/__snapshots__/csr.test.jsx.snap b/test/snap/__snapshots__/csr.test.jsx.snap
index 7be8fe5643..03330fc314 100644
--- a/test/snap/__snapshots__/csr.test.jsx.snap
+++ b/test/snap/__snapshots__/csr.test.jsx.snap
@@ -58547,11 +58547,6 @@ exports[`csr snapshot test > csr test src/list/_example/header-footer.tsx 1`] =
-
-
csr test src/list/_example/header-footer.tsx 1`] =
-
-
`;
@@ -137141,7 +137117,7 @@ exports[`ssr snapshot test > ssr test src/list/_example/asyncLoading.tsx 1`] = `
exports[`ssr snapshot test > ssr test src/list/_example/base.tsx 1`] = `""`;
-exports[`ssr snapshot test > ssr test src/list/_example/header-footer.tsx 1`] = `"列表内容列表内容列表内容
列表内容列表内容列表内容
列表内容列表内容列表内容
列表内容列表内容列表内容
列表内容列表内容列表内容
列表内容列表内容列表内容
列表内容列表内容列表内容
列表内容列表内容列表内容
"`;
+exports[`ssr snapshot test > ssr test src/list/_example/header-footer.tsx 1`] = `"列表内容列表内容列表内容
列表内容列表内容列表内容
列表内容列表内容列表内容
列表内容列表内容列表内容
列表内容列表内容列表内容
列表内容列表内容列表内容
列表内容列表内容列表内容
列表内容列表内容列表内容
"`;
exports[`ssr snapshot test > ssr test src/list/_example/image-text.tsx 1`] = `""`;
diff --git a/test/snap/__snapshots__/ssr.test.jsx.snap b/test/snap/__snapshots__/ssr.test.jsx.snap
index f5dc009379..db82ed901d 100644
--- a/test/snap/__snapshots__/ssr.test.jsx.snap
+++ b/test/snap/__snapshots__/ssr.test.jsx.snap
@@ -592,7 +592,7 @@ exports[`ssr snapshot test > ssr test src/list/_example/asyncLoading.tsx 1`] = `
exports[`ssr snapshot test > ssr test src/list/_example/base.tsx 1`] = `""`;
-exports[`ssr snapshot test > ssr test src/list/_example/header-footer.tsx 1`] = `"列表内容列表内容列表内容
列表内容列表内容列表内容
列表内容列表内容列表内容
列表内容列表内容列表内容
列表内容列表内容列表内容
列表内容列表内容列表内容
列表内容列表内容列表内容
列表内容列表内容列表内容
"`;
+exports[`ssr snapshot test > ssr test src/list/_example/header-footer.tsx 1`] = `"列表内容列表内容列表内容
列表内容列表内容列表内容
列表内容列表内容列表内容
列表内容列表内容列表内容
列表内容列表内容列表内容
列表内容列表内容列表内容
列表内容列表内容列表内容
列表内容列表内容列表内容
"`;
exports[`ssr snapshot test > ssr test src/list/_example/image-text.tsx 1`] = `""`;