mirror of https://github.com/sveltejs/svelte
Merge pull request #501 from sveltejs/gh-498-b
allow dynamic each-block to have static else-blockpull/506/head
commit
6b2c9279cb
@ -0,0 +1,27 @@
|
||||
export default {
|
||||
data: {
|
||||
animals: [ 'alpaca', 'baboon', 'capybara' ]
|
||||
},
|
||||
|
||||
html: `
|
||||
<p>alpaca</p>
|
||||
<p>baboon</p>
|
||||
<p>capybara</p>
|
||||
`,
|
||||
|
||||
test ( assert, component, target ) {
|
||||
component.set({ animals: [] });
|
||||
assert.htmlEqual( target.innerHTML, `
|
||||
<p>no animals</p>
|
||||
` );
|
||||
|
||||
// trigger an 'update' of the else block, to ensure that
|
||||
// non-existent update method is not called
|
||||
component.set({ animals: [] });
|
||||
|
||||
component.set({ animals: ['wombat'] });
|
||||
assert.htmlEqual( target.innerHTML, `
|
||||
<p>wombat</p>
|
||||
` );
|
||||
}
|
||||
};
|
@ -0,0 +1,5 @@
|
||||
{{#each animals as animal}}
|
||||
<p>{{animal}}</p>
|
||||
{{else}}
|
||||
<p>no animals</p>
|
||||
{{/each}}
|
Loading…
Reference in new issue