mirror of https://github.com/sveltejs/svelte
parent
94a230e4c4
commit
439ef8bb57
@ -0,0 +1,38 @@
|
||||
import { tick } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
html: `
|
||||
<button>increment</button>
|
||||
<button>shift</button>
|
||||
<p>0</p>
|
||||
`,
|
||||
|
||||
async test({ assert, target }) {
|
||||
const [increment, shift] = target.querySelectorAll('button');
|
||||
|
||||
increment.click();
|
||||
await tick();
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<button>increment</button>
|
||||
<button>shift</button>
|
||||
<p>1</p>
|
||||
`
|
||||
);
|
||||
|
||||
shift.click();
|
||||
await tick();
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<button>increment</button>
|
||||
<button>shift</button>
|
||||
<p>resolved</p>
|
||||
`
|
||||
);
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,31 @@
|
||||
<script>
|
||||
let resolvers = [];
|
||||
|
||||
function push(value) {
|
||||
const deferred = Promise.withResolvers();
|
||||
resolvers.push(() => deferred.resolve(value));
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function shift() {
|
||||
resolvers.shift()?.();
|
||||
}
|
||||
|
||||
let count = $state(0);
|
||||
</script>
|
||||
|
||||
<button onclick={() => count += 1}>
|
||||
increment
|
||||
</button>
|
||||
|
||||
<button onclick={shift}>
|
||||
shift
|
||||
</button>
|
||||
|
||||
<svelte:boundary>
|
||||
<p>{await push('resolved')}</p>
|
||||
|
||||
{#snippet pending()}
|
||||
<p>{count}</p>
|
||||
{/snippet}
|
||||
</svelte:boundary>
|
||||
Loading…
Reference in new issue