Skip to content

Commit 9586a77

Browse files
committed
test cases for arrow function
1 parent 5310899 commit 9586a77

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

test/rules/prefer-show.test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,51 @@ export const cases = run("prefer-show", rule, {
4545
);
4646
}`,
4747
},
48+
{
49+
code: `
50+
function Component(props) {
51+
return (
52+
<For each={props.someList}>
53+
{(listItem) => listItem.cond && <span>Content</span>}
54+
</For>
55+
);
56+
}`,
57+
errors: [{ messageId: "preferShowAnd" }],
58+
output: `
59+
function Component(props: any) {
60+
return (
61+
<For each={props.someList}>
62+
{(listItem) => <Show when={listItem.cond}><span>Content</span></Show>}
63+
</For>
64+
);
65+
}`,
66+
},
67+
{
68+
code: `
69+
function Component(props) {
70+
return (
71+
<For each={props.someList}>
72+
{(listItem) => (listItem.cond ? (
73+
<span>Content</span>
74+
) : (
75+
<span>Fallback</span>
76+
))}
77+
</For>
78+
);
79+
}`,
80+
errors: [{ messageId: "preferShowTernary" }],
81+
output: `
82+
function Component(props) {
83+
return (
84+
<For each={props.someList}>
85+
{(listItem) => (
86+
<Show when={listItem.cond} fallback={<span>Fallback</span>}>
87+
<span>Content</span>
88+
</Show>
89+
)}
90+
</For>
91+
);
92+
}`,
93+
},
4894
],
4995
});

0 commit comments

Comments
 (0)