Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>