24 lines
1.1 KiB
TypeScript
24 lines
1.1 KiB
TypeScript
import { expect, test } from "bun:test";
|
|
import { parse, generate } from "../src/index.ts";
|
|
|
|
test("native boolean attributes inside conditional and loop bodies use presence semantics", async () => {
|
|
const source = `page Example {
|
|
load server account { return {} }
|
|
view {
|
|
{#if account.visible}<input required disabled="{!account.edit}" />{/if}
|
|
{#each account.rows as row}<input type="checkbox" checked="{row.checked}" disabled="false" />{/each}
|
|
}
|
|
}`;
|
|
const code = new Bun.Transpiler({ loader: "ts" }).transformSync(generate(parse(source)));
|
|
const mod = await import("data:text/javascript;base64," + Buffer.from(code).toString("base64"));
|
|
const html = await mod.default({
|
|
account: { visible: true, edit: true, rows: [{ checked: false }, { checked: true }] },
|
|
});
|
|
expect(html).not.toContain("disabled");
|
|
expect(html).not.toContain('checked="false"');
|
|
expect(html.match(/ checked/g)).toHaveLength(1);
|
|
expect(html).toContain("required");
|
|
const denied = await mod.default({ account: { visible: true, edit: false, rows: [] } });
|
|
expect(denied).toContain(" disabled");
|
|
});
|