mirror of https://github.com/sveltejs/svelte
get context at start of {#if} update block instead of at the end (#5531)
parent
f038cf75fa
commit
a4e4bd0f53
@ -0,0 +1,29 @@
|
||||
export default {
|
||||
props: {
|
||||
thePromise: Promise.resolve({ result: 1 })
|
||||
},
|
||||
|
||||
html: '',
|
||||
|
||||
async test({ assert, component, target }) {
|
||||
await (component.thePromise = Promise.resolve({ result: 1 }));
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<p>result: 1</p>
|
||||
<p>count: 0</p>
|
||||
`
|
||||
);
|
||||
|
||||
await new Promise(resolve => setTimeout(resolve, 1));
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<p>result: 1</p>
|
||||
<p>count: 1</p>
|
||||
`
|
||||
);
|
||||
}
|
||||
};
|
@ -0,0 +1,19 @@
|
||||
<script>
|
||||
export let thePromise;
|
||||
|
||||
let count = 0;
|
||||
|
||||
setTimeout(() => {
|
||||
count++;
|
||||
}, 0);
|
||||
</script>
|
||||
|
||||
{#await thePromise then { result }}
|
||||
{#if result}
|
||||
<p>result: {result}</p>
|
||||
<p>count: {count}</p>
|
||||
{:else}
|
||||
<p>result: {result}</p>
|
||||
<p>count: {count}</p>
|
||||
{/if}
|
||||
{/await}
|
Loading…
Reference in new issue