release: WRNexusJS 0.2.39
This commit is contained in:
@@ -783,3 +783,58 @@ page Home {
|
||||
|
||||
expect(output).toContain("__wrnexusPropAttr([");
|
||||
});
|
||||
test("component functions are available during server rendering", () => {
|
||||
const output = generate(
|
||||
parse(`
|
||||
component FAQAccordion {
|
||||
props {
|
||||
allowMultiple = false
|
||||
items = []
|
||||
}
|
||||
|
||||
state openIndexes = []
|
||||
|
||||
functions {
|
||||
function isOpen(index) {
|
||||
return openIndexes.includes(index)
|
||||
}
|
||||
|
||||
function toggleItem(index) {
|
||||
if (isOpen(index)) {
|
||||
openIndexes = openIndexes.filter(
|
||||
(itemIndex) =>
|
||||
itemIndex !== index
|
||||
)
|
||||
} else if (allowMultiple) {
|
||||
openIndexes = [
|
||||
...openIndexes,
|
||||
index
|
||||
]
|
||||
} else {
|
||||
openIndexes = [index]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
view {
|
||||
{#each items as item, index}
|
||||
<button
|
||||
class:hidden="!isOpen(index)"
|
||||
@click="toggleItem(index)"
|
||||
>
|
||||
{item.title}
|
||||
</button>
|
||||
{/each}
|
||||
}
|
||||
}
|
||||
`),
|
||||
);
|
||||
|
||||
expect(output).toContain("function isOpen(index)");
|
||||
|
||||
expect(output).toContain("function toggleItem(index)");
|
||||
|
||||
expect(output).toContain("let openIndexes =");
|
||||
|
||||
expect(output).toContain("isOpen(index)");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user