import { renderToString, snapshotEverything, TestContext } from "../helpers"; snapshotEverything(); // ----------------------------------------------------------------------------- // Simple templates, mostly static // ----------------------------------------------------------------------------- describe("simple templates, mostly static", () => { test("simple string", () => { const template = `hello vdom`; expect(renderToString(template)).toBe("hello vdom"); }); test("simple string in t tag", () => { const template = `hello vdom`; expect(renderToString(template)).toBe("hello vdom"); }); test("empty string", () => { const template = ``; expect(renderToString(template)).toBe(""); }); test("empty string in a template set", () => { const template = ``; const context = new TestContext(); context.addTemplate("potato", template); expect(context.renderToString("potato")).toBe(""); }); test("empty div", () => { const template = `
`; expect(renderToString(template)).toBe("
"); }); test("div with content", () => { const template = `
foo
`; expect(renderToString(template)).toBe("
foo
"); }); test("multiple root nodes", () => { const template = `
foo
hey`; expect(renderToString(template)).toBe("
foo
hey"); }); test("dynamic text value", () => { const template = ``; expect(renderToString(template, { text: "owl" })).toBe("owl"); }); test("two t-escs next to each other", () => { const template = ``; expect(renderToString(template, { text1: "hello", text2: "owl" })).toBe("helloowl"); }); test("two t-escs next to each other", () => { const template = ``; expect(renderToString(template, { text1: "hello", text2: "owl" })).toBe("helloowl"); }); test("two t-escs next to each other, in a div", () => { const template = `
`; expect(renderToString(template, { text1: "hello", text2: "owl" })).toBe("
helloowl
"); }); test("static text and dynamic text", () => { const template = `hello `; expect(renderToString(template, { text: "owl" })).toBe("hello owl"); }); test("static text and dynamic text (no t tag)", () => { const template = `hello `; expect(renderToString(template, { text: "owl" })).toBe("hello owl"); }); test("t-esc in dom node", () => { const template = `
`; expect(renderToString(template, { text: "hello owl" })).toBe("
hello owl
"); }); test("dom node with t-esc", () => { const template1 = `
`; expect(renderToString(template1, { text: "hello owl" })).toBe("
hello owl
"); const template2 = `
`; expect(renderToString(template2, { text: "hello owl" })).toBe("
hello owl
"); }); test("t-esc in dom node, variations", () => { const template1 = `
hello
`; expect(renderToString(template1, { text: "owl" })).toBe("
hello owl
"); const template2 = `
hello world
`; expect(renderToString(template2, { text: "owl" })).toBe("
hello owl world
"); }); test("div with a class attribute", () => { const template = `
foo
`; expect(renderToString(template)).toBe(`
foo
`); }); test("div with a class attribute with a quote", () => { const template = `
word
`; expect(renderToString(template)).toBe(`
word
`); }); test("div with an arbitrary attribute with a quote", () => { const template = `
word
`; expect(renderToString(template)).toBe(`
word
`); }); test("div with an empty class attribute", () => { const template = `
word
`; expect(renderToString(template)).toBe(`
word
`); }); test("div with a span child node", () => { const template = `
word
`; expect(renderToString(template)).toBe("
word
"); }); test("can render a table row", () => { const template = `cell`; expect(renderToString(template)).toBe(template); }); test("inline template string in t-esc", () => { const template = ''; expect(renderToString(template)).toBe("text"); }); test("inline template string with content in t-esc", () => { const template = ''; expect(renderToString(template)).toBe("text1"); }); test("inline template string with variable in context", () => { const template = ''; expect(renderToString(template, { v: "from context" })).toBe("text from context"); }); test("template with t tag with multiple content", () => { const template = `
Loading
`; expect(renderToString(template)).toBe("
Loading
"); }); test("template with multiple t tag with multiple content", () => { const template = `
Loading
`; expect(renderToString(template, { a: "a", b: "b", c: "c" })).toBe("
abLoadingc
"); }); test("text node with backslash at top level", () => { const template = "\\"; expect(renderToString(template)).toBe("\\"); }); test("text node with backtick at top-level", () => { const template = "`"; expect(renderToString(template)).toBe("`"); }); test("text node with interpolation sigil at top level", () => { const template = "${very cool}"; expect(renderToString(template)).toBe("${very cool}"); }); });