Skip to content

Commit

Permalink
test(looping): Add test for 11ty#179
Browse files Browse the repository at this point in the history
Issue 179:
> bug: “`loopContent.map is not a function (via TypeError)`” 11ty#179
  • Loading branch information
Zearin committed May 21, 2023
1 parent a2f548c commit 5eb2321
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
27 changes: 25 additions & 2 deletions test/looping-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,29 @@ test("webc:for issue #139", async t => {
<b>3</b>`);
});

// looping over iterables that are not Objects or Arrays
test("webc:for issue #179", async t => {
let component = new WebC();

component.setInputPath("./test/stubs/looping/issue-179-iterables.webc");

let { html } = await component.compile();

t.is(html.trim(), `<dl>
<dt>one</dt>
<dd>1</dd>
<dt>two</dt>
<dd>2</dd>
<dt>three</dt>
<dd>3</dd>
</dl>
<ul>
<li>one</li>
<li>two</li>
<li>three</li>
</ul>`);
});

test("script webc:setup feeds data for looping", async t => {
let component = new WebC();

Expand All @@ -119,11 +142,11 @@ test("nesting webc:for over component hierarchy", async t => {
component.setInputPath("./test/stubs/looping/complex/entry-point.webc");

let { html } = await component.compile({data:{contacts}});

t.true(html.indexOf(`<button onclick="alert('Hello Monica')">Say hello</button>`) > -1)
t.true(html.indexOf(`<li>Ross - 1</li>`) > -1)
t.true(html.indexOf(`<div style="border-color:violet">`) > -1)
t.true(html.indexOf(`<div>Chandler</div>`) > -1)
t.true(html.indexOf(`border: 1px solid green;`) > -1)

})
24 changes: 24 additions & 0 deletions test/stubs/looping/issue-179-iterables.webc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<script webc:setup>
const MapData = new Map([
['one', 1],
['two', 2],
['three', 3],
])

const SetData = new Set([
'one',
'two',
'three',
])
</script>
<dl>
<template webc:for="(key, val) of MapData" webc:nokeep>
<dt @text="key"></dt>
<dd @text="val"></dd>
</template>
</dl>
<ul>
<template webc:for="val of SetData" webc:nokeep>
<li @text="val"></li>
</template>
</ul>

0 comments on commit 5eb2321

Please sign in to comment.