mirror of https://github.com/sveltejs/svelte
commit
d4b0999c38
@ -0,0 +1,53 @@
|
||||
let calls = [];
|
||||
function callback(refs) {
|
||||
calls.push(refs.map(({ ref }) => ({ ref })));
|
||||
}
|
||||
export default {
|
||||
html: ``,
|
||||
props: {
|
||||
callback,
|
||||
},
|
||||
after_test() {
|
||||
calls = [];
|
||||
},
|
||||
async test({ assert, component, target }) {
|
||||
assert.equal(calls.length, 1);
|
||||
assert.equal(calls[0].length, 0);
|
||||
|
||||
await component.addItem();
|
||||
|
||||
let divs = target.querySelectorAll("div");
|
||||
|
||||
assert.equal(calls.length, 3);
|
||||
assert.equal(calls[1].length, 1);
|
||||
assert.equal(calls[1][0].ref, null);
|
||||
assert.equal(calls[2].length, 1);
|
||||
assert.equal(calls[2][0].ref, divs[0]);
|
||||
|
||||
await component.addItem();
|
||||
|
||||
divs = target.querySelectorAll("div");
|
||||
|
||||
assert.equal(calls.length, 5);
|
||||
assert.equal(calls[3].length, 2);
|
||||
assert.equal(calls[3][0].ref, divs[0]);
|
||||
assert.equal(calls[3][1].ref, null);
|
||||
assert.equal(calls[4].length, 2);
|
||||
assert.equal(calls[4][0].ref, divs[0]);
|
||||
assert.equal(calls[4][1].ref, divs[1]);
|
||||
|
||||
await component.addItem();
|
||||
|
||||
divs = target.querySelectorAll("div");
|
||||
|
||||
assert.equal(calls.length, 7);
|
||||
assert.equal(calls[5].length, 3);
|
||||
assert.equal(calls[5][0].ref, divs[0]);
|
||||
assert.equal(calls[5][1].ref, divs[1]);
|
||||
assert.equal(calls[5][2].ref, null);
|
||||
assert.equal(calls[6].length, 3);
|
||||
assert.equal(calls[6][0].ref, divs[0]);
|
||||
assert.equal(calls[6][1].ref, divs[1]);
|
||||
assert.equal(calls[6][2].ref, divs[2]);
|
||||
},
|
||||
};
|
@ -0,0 +1,17 @@
|
||||
<script>
|
||||
import { tick } from 'svelte';
|
||||
let refs = [];
|
||||
|
||||
export function addItem() {
|
||||
refs = refs.concat({ ref: null });
|
||||
return tick();
|
||||
}
|
||||
|
||||
export let callback;
|
||||
|
||||
$: callback(refs);
|
||||
</script>
|
||||
|
||||
{#each refs as xxx}
|
||||
<div bind:this={xxx.ref} />
|
||||
{/each}
|
@ -0,0 +1,5 @@
|
||||
<script>
|
||||
export let content;
|
||||
</script>
|
||||
|
||||
{@html content}
|
@ -0,0 +1,33 @@
|
||||
export default {
|
||||
html: `
|
||||
<button>Switch</button>
|
||||
<p>Another first line</p>
|
||||
<p>This line should be last.</p>
|
||||
`,
|
||||
async test({ assert, target, window }) {
|
||||
const btn = target.querySelector("button");
|
||||
const clickEvent = new window.MouseEvent("click");
|
||||
|
||||
await btn.dispatchEvent(clickEvent);
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<button>Switch</button>
|
||||
<p>First line</p>
|
||||
<p>This line should be last.</p>
|
||||
`
|
||||
);
|
||||
|
||||
await btn.dispatchEvent(clickEvent);
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<button>Switch</button>
|
||||
<p>Another first line</p>
|
||||
<p>This line should be last.</p>
|
||||
`
|
||||
);
|
||||
},
|
||||
};
|
@ -0,0 +1,17 @@
|
||||
<script>
|
||||
import RawMustache from './RawMustache.svelte';
|
||||
|
||||
let content1 = `<p>First line</p>`;
|
||||
let content2 = `<p>Another first line</p>`;
|
||||
|
||||
let show = false;
|
||||
$: content = show ? content1 : content2;
|
||||
</script>
|
||||
|
||||
<button on:click={() => show = !show}>
|
||||
Switch
|
||||
</button>
|
||||
|
||||
<RawMustache {content} />
|
||||
|
||||
<p>This line should be last.</p>
|
@ -0,0 +1,2 @@
|
||||
<slot />
|
||||
<p>This line should be last.</p>
|
@ -1,3 +1,33 @@
|
||||
export default {
|
||||
html: `<p>x<span>baz</span></p>`
|
||||
html: `
|
||||
<button>Switch</button>
|
||||
<p>Another first line</p>
|
||||
<p>This line should be last.</p>
|
||||
`,
|
||||
async test({ assert, target, window }) {
|
||||
const btn = target.querySelector("button");
|
||||
const clickEvent = new window.MouseEvent("click");
|
||||
|
||||
await btn.dispatchEvent(clickEvent);
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<button>Switch</button>
|
||||
<p>First line</p>
|
||||
<p>This line should be last.</p>
|
||||
`
|
||||
);
|
||||
|
||||
await btn.dispatchEvent(clickEvent);
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<button>Switch</button>
|
||||
<p>Another first line</p>
|
||||
<p>This line should be last.</p>
|
||||
`
|
||||
);
|
||||
},
|
||||
};
|
||||
|
@ -1 +1,17 @@
|
||||
<p>{@html 'x'}<span>baz</span></p>
|
||||
<script>
|
||||
import Component from './Component.svelte';
|
||||
|
||||
let content1 = `<p>First line</p>`;
|
||||
let content2 = `<p>Another first line</p>`
|
||||
|
||||
let show = false;
|
||||
$: content = show ? content1 : content2;
|
||||
</script>
|
||||
|
||||
<button on:click={() => show = !show}>
|
||||
Switch
|
||||
</button>
|
||||
|
||||
<Component>
|
||||
{@html content}
|
||||
</Component>
|
@ -0,0 +1,3 @@
|
||||
export default {
|
||||
html: `<p>x<span>baz</span></p>`
|
||||
};
|
@ -0,0 +1 @@
|
||||
<p>{@html 'x'}<span>baz</span></p>
|
Loading…
Reference in new issue