mirror of https://github.com/sveltejs/svelte
parent
3e1701024b
commit
983083fb82
@ -0,0 +1,7 @@
|
|||||||
|
<script>
|
||||||
|
let { promise } = $props();
|
||||||
|
|
||||||
|
let value = await promise;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<p>{value}</p>
|
@ -0,0 +1,40 @@
|
|||||||
|
import { tick } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
async test({ assert, target }) {
|
||||||
|
const [toggle, hello] = target.querySelectorAll('button');
|
||||||
|
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<button>toggle</button>
|
||||||
|
<button>hello</button>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
|
||||||
|
toggle.click();
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<button>toggle</button>
|
||||||
|
<button>hello</button>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
|
||||||
|
hello.click();
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<button>toggle</button>
|
||||||
|
<button>hello</button>
|
||||||
|
<p>condition is true</p>
|
||||||
|
<p>hello</p>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,20 @@
|
|||||||
|
<script>
|
||||||
|
import Child from './Child.svelte';
|
||||||
|
|
||||||
|
let condition = $state(false);
|
||||||
|
let deferred = $state(Promise.withResolvers());
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={() => condition = !condition}>toggle</button>
|
||||||
|
<button onclick={() => deferred.resolve('hello')}>hello</button>
|
||||||
|
|
||||||
|
<svelte:boundary>
|
||||||
|
{#if condition}
|
||||||
|
<p>condition is {condition}</p>
|
||||||
|
<Child promise={deferred.promise} />
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#snippet pending()}
|
||||||
|
<p>pending</p>
|
||||||
|
{/snippet}
|
||||||
|
</svelte:boundary>
|
Loading…
Reference in new issue