Skip to content

Commit

Permalink
chore: fix $props.id tests (#15294)
Browse files Browse the repository at this point in the history
* chore: fix `$props.id` tests

* chore: reset uid between tests
  • Loading branch information
paoloricciuti authored Feb 14, 2025
1 parent b6bf735 commit 8b97725
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions packages/svelte/src/internal/client/dom/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ export function append(anchor, dom) {

let uid = 1;

export function reset_props_id() {
uid = 1;
}

/**
* Create (or hydrate) an unique UID for the component instance.
*/
Expand Down
2 changes: 2 additions & 0 deletions packages/svelte/tests/runtime-legacy/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { setup_html_equal } from '../html_equal.js';
import { raf } from '../animation-helpers.js';
import type { CompileOptions } from '#compiler';
import { suite_with_variants, type BaseTest } from '../suite.js';
import { reset_props_id } from '../../src/internal/client/dom/template.js';

type Assert = typeof import('vitest').assert & {
htmlEqual(a: string, b: string, description?: string): void;
Expand Down Expand Up @@ -345,6 +346,7 @@ async function run_test_variant(

if (runes) {
props = proxy({ ...(config.props || {}) });
reset_props_id();
if (manual_hydrate) {
hydrate_fn = () => {
instance = hydrate(mod.default, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ export default test({
`
);
} else {
// `c6` because this runs after the `dom` tests
// (slightly brittle but good enough for now)
assert.htmlEqual(
target.innerHTML,
`
Expand All @@ -53,7 +51,7 @@ export default test({
<p>s2</p>
<p>s3</p>
<p>s4</p>
<p>c6</p>
<p>c1</p>
`
);
}
Expand Down

0 comments on commit 8b97725

Please sign in to comment.