work.suroh.tk/node_modules/@11ty/eleventy/test/TemplateRenderHTMLTest.js

52 lines
1.7 KiB
JavaScript
Raw Normal View History

2019-12-02 12:22:45 +00:00
import test from "ava";
import TemplateRender from "../src/TemplateRender";
// HTML
test("HTML", t => {
t.is(new TemplateRender("html").getEngineName(), "html");
});
test("HTML Render", async t => {
let fn = await new TemplateRender("html").getCompiledTemplate(
"<p>Paragraph</p>"
);
t.is(await fn(), "<p>Paragraph</p>");
t.is(await fn({}), "<p>Paragraph</p>");
});
test("HTML Render: Parses HTML using liquid engine (default, with data)", async t => {
let fn = await new TemplateRender("html").getCompiledTemplate(
"<h1>{{title}}</h1>"
);
t.is((await fn({ title: "My Title" })).trim(), "<h1>My Title</h1>");
});
test("HTML Render: Parses HTML using ejs engine", async t => {
let tr = new TemplateRender("html");
tr.setHtmlEngine("ejs");
let fn = await tr.getCompiledTemplate("<h1><%=title %></h1>");
t.is((await fn({ title: "My Title" })).trim(), "<h1>My Title</h1>");
});
test("HTML Render: Set HTML engine to false, dont parse", async t => {
let tr = new TemplateRender("html");
tr.setHtmlEngine(false);
let fn = await tr.getCompiledTemplate("<h1>{{title}}</h1>");
t.is((await fn()).trim(), "<h1>{{title}}</h1>");
});
test("HTML Render: Pass in an override (ejs)", async t => {
let tr = new TemplateRender("html");
tr.setHtmlEngine("ejs");
let fn = await tr.getCompiledTemplate("<h1><%= title %></h1>");
t.is((await fn({ title: "My Title" })).trim(), "<h1>My Title</h1>");
});
test("HTML Render: Pass in an override (liquid)", async t => {
let tr = new TemplateRender("html");
tr.setHtmlEngine("liquid");
let fn = await tr.getCompiledTemplate("<h1>{{title}}</h1>");
t.is((await fn({ title: "My Title" })).trim(), "<h1>My Title</h1>");
});