Skip to content

Commit

Permalink
Fixing sveltejs#2668, add test case "each-block-keyed-containing-self…
Browse files Browse the repository at this point in the history
…-in-if-with-else-branch"
  • Loading branch information
IOuser committed May 14, 2019
1 parent 25c57a2 commit 5ff1f82
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
export let item;
</script>

<span>{item.id}</span>
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
export default {
props: {
list: [
{ id: 1 },
{ id: 2 },
{ id: 3, children: [{ id: 30 }, { id: 31 }, { id: 32 }] },
],
activeId: null,
},

html: `
<ul>
<li><span>1</span><span>foo</span></li>
<li><span>2</span><span>foo</span></li>
<li><span>3</span><span>foo</span></li>
</ul>
`,

test({ assert, component, target }) {
component.activeId = 3;

assert.htmlEqual(target.innerHTML, `
<ul>
<li><span>1</span><span>foo</span></li>
<li><span>2</span><span>foo</span></li>
<li>
<span>3</span>
<ul>
<li><span>30</span><span>foo</span></li>
<li><span>31</span><span>foo</span></li>
<li><span>32</span><span>foo</span></li>
</ul>
</li>
</ul>
`);


component.activeId = null;

assert.htmlEqual(target.innerHTML, `
<ul>
<li><span>1</span><span>foo</span></li>
<li><span>2</span><span>foo</span></li>
<li><span>3</span><span>foo</span></li>
</ul>
`);
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<script>
import Nested from './Nested.svelte';

export let list;
export let activeId;
</script>

<ul>
{#each list as item (item.id)}
<li>
<Nested {item} />
{#if item.id === activeId && item.children}
<svelte:self list={item.children} />
{:else}
<span>foo</span>
{/if}
</li>
{/each}
</ul>

0 comments on commit 5ff1f82

Please sign in to comment.