mirror of https://github.com/sveltejs/svelte
parent
0b2ef3c2a4
commit
9eece0e4a7
@ -0,0 +1,81 @@
|
|||||||
|
import { tick } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
async test({ assert, target }) {
|
||||||
|
const [increment, shift] = target.querySelectorAll('button');
|
||||||
|
|
||||||
|
shift.click();
|
||||||
|
shift.click();
|
||||||
|
shift.click();
|
||||||
|
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<button>increment</button>
|
||||||
|
<button>shift</button>
|
||||||
|
<p>0</p>
|
||||||
|
<p>0</p>
|
||||||
|
<p>0</p>
|
||||||
|
<p>pending: 0</p>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
|
||||||
|
increment.click();
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<button>increment</button>
|
||||||
|
<button>shift</button>
|
||||||
|
<p>0</p>
|
||||||
|
<p>0</p>
|
||||||
|
<p>0</p>
|
||||||
|
<p>pending: 3</p>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
|
||||||
|
shift.click();
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<button>increment</button>
|
||||||
|
<button>shift</button>
|
||||||
|
<p>0</p>
|
||||||
|
<p>0</p>
|
||||||
|
<p>0</p>
|
||||||
|
<p>pending: 2</p>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
|
||||||
|
shift.click();
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<button>increment</button>
|
||||||
|
<button>shift</button>
|
||||||
|
<p>0</p>
|
||||||
|
<p>0</p>
|
||||||
|
<p>0</p>
|
||||||
|
<p>pending: 1</p>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
|
||||||
|
shift.click();
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<button>increment</button>
|
||||||
|
<button>shift</button>
|
||||||
|
<p>1</p>
|
||||||
|
<p>1</p>
|
||||||
|
<p>1</p>
|
||||||
|
<p>pending: 0</p>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,32 @@
|
|||||||
|
<script>
|
||||||
|
let value = $state(0);
|
||||||
|
let deferreds = [];
|
||||||
|
|
||||||
|
function push(value) {
|
||||||
|
const deferred = Promise.withResolvers();
|
||||||
|
deferreds.push({ value, deferred });
|
||||||
|
return deferred.promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
function shift() {
|
||||||
|
const d = deferreds.shift();
|
||||||
|
d?.deferred.resolve(d.value);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={() => value++}>increment</button>
|
||||||
|
<button onclick={() => shift()}>shift</button>
|
||||||
|
|
||||||
|
<svelte:boundary>
|
||||||
|
<p>{await push(value)}</p>
|
||||||
|
<p>{await push(value)}</p>
|
||||||
|
<p>{await push(value)}</p>
|
||||||
|
|
||||||
|
<p>pending: {$effect.pending()}</p>
|
||||||
|
|
||||||
|
{#snippet pending()}
|
||||||
|
<p>loading...</p>
|
||||||
|
{/snippet}
|
||||||
|
</svelte:boundary>
|
||||||
|
|
||||||
|
|
Loading…
Reference in new issue