mirror of https://github.com/sveltejs/svelte
parent
bc10186b69
commit
edec6cd0da
@ -0,0 +1,16 @@
|
|||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
html: `<button>increment</button><p>loading...</p>`,
|
||||||
|
|
||||||
|
async test({ assert, target }) {
|
||||||
|
const [button] = target.querySelectorAll('button');
|
||||||
|
|
||||||
|
await new Promise((f) => setTimeout(f)); // TODO replace with `tick` once `await` lands
|
||||||
|
assert.htmlEqual(target.innerHTML, '<button>increment</button><p>0</p>');
|
||||||
|
|
||||||
|
button.click();
|
||||||
|
await new Promise((f) => setTimeout(f)); // TODO replace with `tick` once `await` lands
|
||||||
|
assert.htmlEqual(target.innerHTML, '<button>increment</button><p>2</p>');
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,27 @@
|
|||||||
|
<script>
|
||||||
|
import { getAbortSignal } from 'svelte';
|
||||||
|
|
||||||
|
let count = $state(0);
|
||||||
|
|
||||||
|
let delayed_count = $derived.by(async () => {
|
||||||
|
const response = await fetch(`data:text/plain;charset=utf-8,${count}`, {
|
||||||
|
signal: getAbortSignal()
|
||||||
|
});
|
||||||
|
|
||||||
|
return await response.json();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={async () => {
|
||||||
|
count += 1;
|
||||||
|
await Promise.resolve();
|
||||||
|
count += 1;
|
||||||
|
}}>increment</button>
|
||||||
|
|
||||||
|
{#await delayed_count}
|
||||||
|
<p>loading...</p>
|
||||||
|
{:then count}
|
||||||
|
<p>{count}</p>
|
||||||
|
{:catch error}
|
||||||
|
{console.log('this should never be rendered')}
|
||||||
|
{/await}
|
Loading…
Reference in new issue