import { renderToString, snapshotEverything } from "../helpers"; snapshotEverything(); // ----------------------------------------------------------------------------- // t-set // ----------------------------------------------------------------------------- describe("t-set", () => { test("set from attribute literal", () => { const template = `
`; expect(renderToString(template)).toBe("
ok
"); }); test("set from attribute literal (no outside div)", () => { const template = ``; expect(renderToString(template)).toBe("ok"); }); test("t-set and t-if", () => { const template = `
grimbergen
`; expect(renderToString(template, { value: "ok" })).toBe("
grimbergen
"); }); test("set from body literal", () => { const template = `ok`; expect(renderToString(template)).toBe("ok"); }); test("set from attribute lookup", () => { const template = `
`; expect(renderToString(template, { value: "ok" })).toBe("
ok
"); }); test("t-set evaluates an expression only once", () => { const template = `
`; expect(renderToString(template, { value: "stella" })).toBe( "
stella artoisstella artois
" ); }); test("set from body lookup", () => { const template = `
`; expect(renderToString(template, { value: "ok" })).toBe("
ok
"); }); test("set from empty body", () => { const template = `
`; expect(renderToString(template)).toBe("
"); }); test("value priority", () => { const template = `
2
`; expect(renderToString(template)).toBe("
1
"); }); test("value priority (with non text body", () => { const template = `
2
`; expect(renderToString(template)).toBe("
1
"); }); test("evaluate value expression", () => { const template = `
`; expect(renderToString(template)).toBe("
3
"); }); test("t-set should reuse variable if possible", () => { const template = `
v
`; const expected = "
v1
va
"; expect(renderToString(template, { list: ["a", "b"] })).toBe(expected); }); test("t-set with content and sub t-esc", () => { const template = `
boop
`; expect(renderToString(template, { beep: "beep" })).toBe("
beep boop
"); }); test("evaluate value expression, part 2", () => { const template = `
`; expect(renderToString(template, { somevariable: 43 })).toBe("
45
"); }); test("t-set, t-if, and mix of expression/body lookup, 1", () => { const template = `
1
`; expect(renderToString(template, { flag: true })).toBe("
1
"); expect(renderToString(template, { flag: false })).toBe("
0
"); }); test("t-set, t-if, and mix of expression/body lookup, 2", () => { const template = `
0
`; expect(renderToString(template, { flag: true })).toBe("
1
"); expect(renderToString(template, { flag: false })).toBe("
0
"); }); test("t-set, t-if, and mix of expression/body lookup, 3", () => { const template = ` 0 `; expect(renderToString(template, { flag: true })).toBe("1"); expect(renderToString(template, { flag: false })).toBe("0"); }); test("t-set body is evaluated immediately", () => { const template = `
`; expect(renderToString(template)).toBe("
before
"); }); test("t-set with t-value (falsy) and body", () => { const template = `
`; expect(renderToString(template)).toBe("
before
"); }); test("t-set with t-value (truthy) and body", () => { const template = `
`; expect(renderToString(template)).toBe("
Truthy
"); }); });