Skip to content

Commit

Permalink
test: add test for #959
Browse files Browse the repository at this point in the history
  • Loading branch information
MoustaphaDev committed Feb 6, 2024
1 parent 15d68f5 commit 9d40796
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion internal/printer/printer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,43 @@ func TestPrinter(t *testing.T) {
},
},
{
name: "function expression slots",
name: "function expression slots I",
source: "<Component>\n{() => { switch (value) {\ncase 'a': return <div slot=\"a\">A</div>\ncase 'b': return <div slot=\"b\">B</div>\ncase 'c': return <div slot=\"c\">C</div>\n}\n}}\n</Component>",
want: want{
code: "${$$renderComponent($$result,'Component',Component,{},$$mergeSlots({},() => { switch (value) {\ncase 'a': return {\"a\": () => $$render`${$$maybeRenderHead($$result)}<div>A</div>`}\ncase 'b': return {\"b\": () => $$render`<div>B</div>`}\ncase 'c': return {\"c\": () => $$render`<div>C</div>`}}\n}))}",
},
},
{
name: "function expression slots II (#959)",
source: `<Layout title="Welcome to Astro.">
<main>
<Layout title="switch bug">
{components.map((component, i) => {
switch(component) {
case "Hero":
return <div>Hero</div>
case "Component2":
return <div>Component2</div>
}
})}
</Layout>
</main>
</Layout>`,
want: want{
code: `${$$renderComponent($$result,'Layout',Layout,{"title":"Welcome to Astro."},{"default": () => $$render` + BACKTICK + `
${$$maybeRenderHead($$result)}<main>
${$$renderComponent($$result,'Layout',Layout,{"title":"switch bug"},{"default": () => $$render` + BACKTICK + `${components.map((component, i) => {
switch(component) {
case "Hero":
return $$render` + BACKTICK + `<div>Hero</div>` + BACKTICK + `
case "Component2":
return $$render` + BACKTICK + `<div>Component2</div>` + BACKTICK + `
}
})}` + BACKTICK + `,})}
</main>
` + BACKTICK + `,})}`,
},
},
{
name: "expression slot",
source: `<Component>{true && <div slot="a">A</div>}{false && <div slot="b">B</div>}</Component>`,
Expand Down

0 comments on commit 9d40796

Please sign in to comment.