import { renderToString, snapshotEverything, TestContext } from "../helpers";
snapshotEverything();
// -----------------------------------------------------------------------------
// t-raw
// -----------------------------------------------------------------------------
describe("t-raw", () => {
test("literal", () => {
const template = ``;
expect(renderToString(template)).toBe("ok");
});
test("literal, no outside html element", () => {
const template = ``;
expect(renderToString(template)).toBe("ok");
});
test("variable", () => {
const template = ``;
expect(renderToString(template, { var: "ok" })).toBe("ok");
});
test("not escaping", () => {
const template = `
`;
expect(renderToString(template, { var: "" })).toBe("
");
});
test("t-raw and another sibling node", () => {
const template = `hello`;
expect(renderToString(template, { var: "world" })).toBe(
"helloworld"
);
});
test("t-raw with comment", () => {
const template = ``;
expect(renderToString(template, { var: "text
" })).toBe(
"text
"
);
});
test("t-raw on a node with a body, as a default", () => {
const template = `nope`;
expect(renderToString(template)).toBe("nope");
});
test("t-raw with a in body", () => {
const template = ``;
expect(renderToString(template, { var: "coucou" })).toBe("coucou");
});
test("t-raw with just a t-set t-value in body", () => {
const template = ``;
expect(renderToString(template, { var: "coucou" })).toBe("coucou");
});
test("t-raw on a node with a dom node in body, as a default", () => {
const template = `nope
`;
expect(renderToString(template)).toBe("nope
");
});
test("multiple calls to t-raw", () => {
const context = new TestContext();
const sub = `
`;
const main = `
coucou
`;
context.addTemplate("sub", sub);
context.addTemplate("main", main);
const expected =
"";
expect(context.renderToString("main")).toBe(expected);
});
});