Skip to content

Commit 9af6013

Browse files
tests
1 parent 640fabd commit 9af6013

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { tick } from 'svelte';
2+
import { test } from '../../test';
3+
4+
export default test({
5+
skip_no_async: true,
6+
mode: ['async-server', 'hydrate'],
7+
8+
server_props: { environment: 'server' },
9+
ssrHtml:
10+
'<div>did you ever hear the tragedy of darth plagueis the wise?</div><div>Loading...</div>',
11+
12+
test_ssr({ assert, warnings }) {
13+
assert.strictEqual(warnings.length, 1);
14+
// for some strange reason we trim the error code off the beginning of warnings so I can't actually assert it
15+
assert.include(warnings[0], 'A `hydratable` value with key `partially_used`');
16+
},
17+
18+
async test({ assert, target }) {
19+
// make sure the hydratable promise on the client has a chance to run and reject (it shouldn't, because the server data should be used)
20+
await tick();
21+
22+
assert.htmlEqual(
23+
target.innerHTML,
24+
'<div>did you ever hear the tragedy of darth plagueis the wise?</div><div>no, sith daddy, please tell me</div>'
25+
);
26+
}
27+
});
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<script lang="ts">
2+
import { hydratable } from "svelte";
3+
4+
const { environment } = $props();
5+
6+
const partially_used_hydratable = hydratable(
7+
"partially_used",
8+
() => {
9+
return {
10+
used: new Promise(
11+
(res, rej) => environment === 'server' ? setTimeout(() => res('did you ever hear the tragedy of darth plagueis the wise?'), 0) : rej('should not run')
12+
),
13+
unused: new Promise(
14+
(res, rej) => environment === 'server' ? setTimeout(() => res('no, sith daddy, please tell me'), 0) : rej('should not run')
15+
),
16+
}
17+
}
18+
);
19+
</script>
20+
21+
<div>{await partially_used_hydratable.used}</div>
22+
<svelte:boundary>
23+
<div>{await partially_used_hydratable.unused}</div>
24+
{#snippet pending()}
25+
<div>Loading...</div>
26+
{/snippet}
27+
</svelte:boundary>

0 commit comments

Comments
 (0)