import test from "ava"; import TemplateRender from "../src/TemplateRender"; // Mustache test("Mustache", async t => { t.is(new TemplateRender("mustache").getEngineName(), "mustache"); }); test("Mustache Render", async t => { let fn = await new TemplateRender("mustache").getCompiledTemplate( "

{{name}}

" ); t.is(await fn({ name: "Zach" }), "

Zach

"); }); test("Mustache Render Partial (raw text content)", async t => { let fn = await new TemplateRender( "mustache", "./test/stubs/" ).getCompiledTemplate("

{{> included}}

"); t.is(await fn(), "

This is an include.

"); }); test.skip("Mustache Render Partial (relative path, raw text content)", async t => { let fn = await new TemplateRender( "./test/stubs/does_not_exist_and_thats_ok.mustache", "./test/stubs/" ).getCompiledTemplate("

{{> ./includedrelative}}

"); t.is(await fn(), "

This is an includdde.

"); }); test("Mustache Render Partial (uses a variable in content)", async t => { let fn = await new TemplateRender( "mustache", "./test/stubs/" ).getCompiledTemplate("

{{> includedvar}}

"); t.is(await fn({ name: "Zach" }), "

This is a Zach.

"); }); test("Mustache Render Partial (Subdirectory)", async t => { let fn = await new TemplateRender( "mustache", "./test/stubs/" ).getCompiledTemplate("

{{> subfolder/included}}

"); t.is(await fn({ name: "Zach" }), "

This is an include.

"); }); test("Mustache Render: with Library Override", async t => { let tr = new TemplateRender("mustache"); let lib = require("mustache"); tr.engine.setLibrary(lib); let fn = await tr.getCompiledTemplate("

{{name}}

"); t.is(await fn({ name: "Zach" }), "

Zach

"); }); test("Mustache Render Unescaped Output (no HTML)", async t => { let fn = await new TemplateRender("mustache").getCompiledTemplate( "

{{{name}}}

" ); t.is(await fn({ name: "Zach" }), "

Zach

"); }); test("Mustache Render Escaped Output", async t => { let fn = await new TemplateRender("mustache").getCompiledTemplate( "

{{name}}

" ); t.is( await fn({ name: "Zach" }), "

<b>Zach</b>

" ); }); test("Mustache Render Unescaped Output (HTML)", async t => { let fn = await new TemplateRender("mustache").getCompiledTemplate( "

{{{name}}}

" ); t.is(await fn({ name: "Zach" }), "

Zach

"); });