Skip to content

Commit

Permalink
Tests for #524.
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Jun 18, 2019
1 parent e127ca1 commit f3ee437
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
55 changes: 55 additions & 0 deletions test/TemplateRenderNunjucksTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,58 @@ test("Nunjucks Shortcode Named Args (JS notation)", async t => {
"testhowdyZach"
);
});

test("Nunjucks Test if statements on arrays (Issue #524)", async t => {
let tr = new TemplateRender("njk", "./test/stubs/");

t.is(
await tr.render("{% if 'first' in tags %}Success.{% endif %}", {
tags: ["first", "second"]
}),
"Success."
);

t.is(
await tr.render("{% if 'sdfsdfs' in tags %}{% else %}Success.{% endif %}", {
tags: ["first", "second"]
}),
"Success."
);

t.is(
await tr.render(
"{% if false %}{% elseif 'first' in tags %}Success.{% endif %}",
{
tags: ["first", "second"]
}
),
"Success."
);

t.is(
await tr.render("{% if tags.includes('first') %}Success.{% endif %}", {
tags: ["first", "second"]
}),
"Success."
);

t.is(
await tr.render(
"{% if tags.includes('dsds') %}{% else %}Success.{% endif %}",
{
tags: ["first", "second"]
}
),
"Success."
);

t.is(
await tr.render(
"{% if false %}{% elseif tags.includes('first') %}Success.{% endif %}",
{
tags: ["first", "second"]
}
),
"Success."
);
});
12 changes: 12 additions & 0 deletions test/TemplateTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,12 @@ test("Front Matter Tags (Single)", async t => {
);
let frontmatter = await tmpl.getFrontMatterData();
t.deepEqual(frontmatter.tags, ["single-tag"]);

let fulldata = await tmpl.getData();
t.deepEqual(fulldata.tags, ["single-tag"]);

let pages = await tmpl.getRenderedTemplates(fulldata);
t.is(pages[0].templateContent.trim(), "Has single-tag");
});

test("Front Matter Tags (Multiple)", async t => {
Expand All @@ -1242,6 +1248,12 @@ test("Front Matter Tags (Multiple)", async t => {
);
let frontmatter = await tmpl.getFrontMatterData();
t.deepEqual(frontmatter.tags, ["multi-tag", "multi-tag-2"]);

let fulldata = await tmpl.getData();
t.deepEqual(fulldata.tags, ["multi-tag", "multi-tag-2"]);

let pages = await tmpl.getRenderedTemplates(fulldata);
t.is(pages[0].templateContent.trim(), "Has multi-tag-2");
});

test("Front matter date with quotes (liquid), issue #258", async t => {
Expand Down
1 change: 1 addition & 0 deletions test/stubs/templatetest-frontmatter/multiple.njk
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ tags:
- multi-tag
- multi-tag-2
---
{% if tags.includes("multi-tag-2") %}Has multi-tag-2{% endif %}
1 change: 1 addition & 0 deletions test/stubs/templatetest-frontmatter/single.njk
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
tags: single-tag
---
{% if tags.includes("single-tag") %}Has single-tag{% endif %}

0 comments on commit f3ee437

Please sign in to comment.