beef up test

pull/12425/head
Rich Harris 2 years ago
parent 5f77f80c6d
commit 4e7279af5e

@ -1,8 +1,17 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
compileOptions: {
dev: true // Render in dev mode to check that the validation error is not thrown
},
html: `<p>hello world</p>`
html: `<button>click</button><p>clicks: 0</p>`,
test({ target, assert }) {
const button = target.querySelector('button');
flushSync(() => button?.click());
assert.htmlEqual(target.innerHTML, `<button>click</button><p>clicks: 1</p>`);
}
});

@ -1,16 +1,24 @@
<script>
import { createRawSnippet } from 'svelte';
let count = $state(0);
const hello = createRawSnippet({
mount() {
mount(count) {
const p = document.createElement('p')
p.textContent = 'hello world';
$effect(() => {
p.textContent = `clicks: ${count()}`
});
return p;
},
render() {
return '<p>hello world</p>';
render(count) {
return `<p>clicks: ${count}</p>`;
}
});
</script>
{@render hello()}
<button onclick={() => count += 1}>click</button>
{@render hello(count)}

Loading…
Cancel
Save