Skip to content

Commit cdec2d3

Browse files
committed
type tests
1 parent 14f1993 commit cdec2d3

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

test-d/index.test-d.tsx

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import {
1313
Image,
1414
RootClass,
1515
BodyClass,
16+
intersperse,
17+
Join,
1618
} from '../index.js';
1719

1820
class Bar extends ReactComponent {
@@ -85,3 +87,45 @@ const RootTest = (props: {isDarkMode: boolean}) => (
8587
<BodyClass add='logged-in paid-user' remove='promo'/>
8688
</If>
8789
);
90+
91+
// Test intersperse function
92+
const items = ['Apple', 'Orange', 'Banana'].map(item => <li key={item}>{item}</li>);
93+
94+
// Test with array of ReactNodes
95+
expectType<React.ReactNode[]>(intersperse(items, ', '));
96+
97+
// Test with single ReactNode
98+
expectType<React.ReactNode[]>(intersperse(<div>single</div>, ', '));
99+
100+
// Test with separator function
101+
expectType<React.ReactNode[]>(intersperse(items, (index, count) =>
102+
index === count - 2 ? ' and ' : ', ',
103+
));
104+
105+
// Test with no separator
106+
expectType<React.ReactNode[]>(intersperse(items));
107+
108+
// Test Join component
109+
const JoinTest = (
110+
<Join>
111+
<li>Apple</li>
112+
<li>Orange</li>
113+
<li>Banana</li>
114+
</Join>
115+
);
116+
117+
const JoinWithCustomSeparator = (
118+
<Join separator=' | '>
119+
<a href='#'>Home</a>
120+
<a href='#'>About</a>
121+
<a href='#'>Contact</a>
122+
</Join>
123+
);
124+
125+
const JoinWithFunctionSeparator = (
126+
<Join separator={(index, count) => index === count - 2 ? ' and ' : ', '}>
127+
<span>Apple</span>
128+
<span>Orange</span>
129+
<span>Banana</span>
130+
</Join>
131+
);

0 commit comments

Comments
 (0)