mirror of https://github.com/sveltejs/svelte
parent
cfccffd948
commit
2903ba9d8f
@ -0,0 +1,19 @@
|
||||
import { tick } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
solo: true,
|
||||
async test({ assert, target }) {
|
||||
const btn = target.querySelector('button');
|
||||
|
||||
assert.htmlEqual(target.innerHTML, `<button>fork</button>`);
|
||||
|
||||
btn?.click();
|
||||
await tick();
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`<button>fork</button> <div>portaled</div> <div>portaled</div>`
|
||||
);
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,20 @@
|
||||
<script>
|
||||
import { fork } from 'svelte';
|
||||
|
||||
let show = $state(false);
|
||||
</script>
|
||||
|
||||
<button onclick={async () => {
|
||||
fork(() => {
|
||||
show = true;
|
||||
}).commit();
|
||||
}}>fork</button>
|
||||
|
||||
{#portal 'target'}
|
||||
portaled
|
||||
{/portal}
|
||||
|
||||
{#if show}
|
||||
<div>{@portal 'target'}</div>
|
||||
<div>{@portal 'target'}</div>
|
||||
{/if}
|
||||
@ -0,0 +1,63 @@
|
||||
import { tick } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
async test({ assert, target }) {
|
||||
await tick();
|
||||
const [togglePortalKey, toggleOutletKey, shift, pop, commit] =
|
||||
target.querySelectorAll('button');
|
||||
|
||||
togglePortalKey.click();
|
||||
await tick();
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
'<button>toggle portalKey</button> <button>toggle outletKey</button> <button>shift</button> <button>pop</button> <button>commit</button> ab'
|
||||
);
|
||||
|
||||
toggleOutletKey.click();
|
||||
await tick();
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
'<button>toggle portalKey</button> <button>toggle outletKey</button> <button>shift</button> <button>pop</button> <button>commit</button> ab'
|
||||
);
|
||||
|
||||
shift.click();
|
||||
await tick();
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
'<button>toggle portalKey</button> <button>toggle outletKey</button> <button>shift</button> <button>pop</button> <button>commit</button> bb hi'
|
||||
);
|
||||
|
||||
shift.click();
|
||||
await tick();
|
||||
shift.click();
|
||||
await tick();
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
'<button>toggle portalKey</button> <button>toggle outletKey</button> <button>shift</button> <button>pop</button> <button>commit</button> bb hi'
|
||||
);
|
||||
|
||||
commit.click();
|
||||
await tick();
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
'<button>toggle portalKey</button> <button>toggle outletKey</button> <button>shift</button> <button>pop</button> <button>commit</button> ba'
|
||||
);
|
||||
|
||||
toggleOutletKey.click();
|
||||
await tick();
|
||||
shift.click();
|
||||
await tick();
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
'<button>toggle portalKey</button> <button>toggle outletKey</button> <button>shift</button> <button>pop</button> <button>commit</button> ba'
|
||||
);
|
||||
|
||||
commit.click();
|
||||
await tick();
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
'<button>toggle portalKey</button> <button>toggle outletKey</button> <button>shift</button> <button>pop</button> <button>commit</button> bb hi'
|
||||
);
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,35 @@
|
||||
<script>
|
||||
import { fork } from "svelte";
|
||||
|
||||
let portalKey = $state('a');
|
||||
let outletKey = $state('b');
|
||||
|
||||
let queued = [];
|
||||
let first = true;
|
||||
let f;
|
||||
|
||||
function push(v) {
|
||||
if (first) {
|
||||
first = false;
|
||||
return v;
|
||||
}
|
||||
|
||||
return new Promise((resolve) => {
|
||||
queued.push(() => resolve(v));
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<button onclick={() => portalKey = portalKey === 'a' ? 'b' : 'a'}>toggle portalKey</button>
|
||||
<button onclick={() => f = fork(() => outletKey = outletKey === 'a' ? 'b' : 'a')}>toggle outletKey</button>
|
||||
<button onclick={() => queued.shift()?.()}>shift</button>
|
||||
<button onclick={() => queued.pop()?.()}>pop</button>
|
||||
<button onclick={() => f.commit()}>commit</button>
|
||||
|
||||
{await push(portalKey + outletKey)}
|
||||
|
||||
{#portal portalKey}
|
||||
hi
|
||||
{/portal}
|
||||
|
||||
{@portal outletKey}
|
||||
Loading…
Reference in new issue