Skip to content

Commit 6bf6c74

Browse files
committed
test
1 parent 8f8a5b1 commit 6bf6c74

File tree

4 files changed

+72
-2
lines changed

4 files changed

+72
-2
lines changed

packages/svelte/tests/runtime-legacy/shared.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,11 @@ async function run_test_variant(
278278
});
279279

280280
if (htmlAttributes) {
281-
for (const [key, value] of htmlAttributes.split(' ').map((attr) => attr.split('='))) {
282-
window.document.documentElement.setAttribute(key, value.slice(1, -1));
281+
for (const [key, value] of htmlAttributes.split('" ').map((attr) => attr.split('='))) {
282+
window.document.documentElement.setAttribute(
283+
key,
284+
value.slice(1, value.endsWith('"') ? -1 : undefined)
285+
);
283286
}
284287
}
285288

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { flushSync } from 'svelte';
2+
import { test } from '../../test';
3+
4+
export default test({
5+
compileOptions: {
6+
dev: true
7+
},
8+
async test({ assert, warnings }) {
9+
assert.include(warnings[0], "Duplicate attribute 'foo' across multiple `<svelte:html>` blocks");
10+
assert.deepEqual(document.documentElement.getAttribute('foo'), 'bar');
11+
assert.deepEqual(document.documentElement.getAttribute('class'), 'foo bar foo baz');
12+
13+
const [btn1, btn2] = document.querySelectorAll('button');
14+
15+
btn1.click();
16+
flushSync();
17+
assert.deepEqual(document.documentElement.getAttribute('foo'), 'foo');
18+
assert.deepEqual(document.documentElement.getAttribute('class'), 'foo bar');
19+
20+
btn1.click();
21+
flushSync();
22+
assert.deepEqual(document.documentElement.getAttribute('foo'), 'bar');
23+
assert.deepEqual(document.documentElement.getAttribute('class'), 'foo bar foo baz');
24+
25+
btn2.click();
26+
flushSync();
27+
assert.deepEqual(document.documentElement.getAttribute('foo'), 'top0');
28+
29+
btn1.click();
30+
flushSync();
31+
assert.deepEqual(document.documentElement.getAttribute('foo'), 'top0');
32+
33+
btn1.click();
34+
flushSync();
35+
assert.deepEqual(document.documentElement.getAttribute('foo'), 'bar');
36+
37+
document.querySelectorAll('button')[2].click();
38+
flushSync();
39+
assert.deepEqual(document.documentElement.getAttribute('foo'), 'nested0');
40+
41+
btn1.click();
42+
flushSync();
43+
assert.deepEqual(document.documentElement.getAttribute('foo'), 'top0');
44+
}
45+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script>
2+
let foo = $state('bar');
3+
let i = 0;
4+
</script>
5+
6+
<button onclick={() => foo = 'nested'+i++}>change nested</button>
7+
<svelte:html {foo} class="foo baz"></svelte:html>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<script>
2+
import Child from './child.svelte';
3+
let foo = $state('foo');
4+
let show = $state(true);
5+
let i = 0;
6+
</script>
7+
8+
<button onclick={() => show = !show}>toggle</button>
9+
<button onclick={() => foo = 'top'+i++}>change top</button>
10+
11+
<svelte:html {foo} class="foo bar"></svelte:html>
12+
13+
{#if show}
14+
<Child />
15+
{/if}

0 commit comments

Comments
 (0)