diff --git a/packages/svelte/src/reactivity/url-search-params.test.ts b/packages/svelte/src/reactivity/url-search-params.test.ts index d93b4b964e..12ab7fbc47 100644 --- a/packages/svelte/src/reactivity/url-search-params.test.ts +++ b/packages/svelte/src/reactivity/url-search-params.test.ts @@ -22,6 +22,7 @@ test('URLSearchParams.set', () => { }); flushSync(() => { + // nothing should happen here params.set('a', 'c'); }); @@ -45,6 +46,7 @@ test('URLSearchParams.append', () => { }); flushSync(() => { + // nothing should happen here params.set('a', 'b'); }); @@ -72,6 +74,7 @@ test('URLSearchParams.delete', () => { }); flushSync(() => { + // nothing should happen here params.delete('a'); }); @@ -123,6 +126,7 @@ test('URLSearchParams.getAll', () => { log.push(params.get('a')); }); render_effect(() => { + // this should only logged once because other changes shouldn't affect this log.push(params.get('c')); }); render_effect(() => { diff --git a/packages/svelte/src/reactivity/url.test.ts b/packages/svelte/src/reactivity/url.test.ts index da88358f8c..174a767781 100644 --- a/packages/svelte/src/reactivity/url.test.ts +++ b/packages/svelte/src/reactivity/url.test.ts @@ -73,3 +73,40 @@ test('url.searchParams', () => { cleanup(); }); + +test('url.href', () => { + const url = new ReactiveURL('https://svelte.dev?foo=bar&t=123'); + const log: any = []; + + const cleanup = effect_root(() => { + render_effect(() => { + log.push(url.href); + }); + }); + + flushSync(() => { + url.search = '?q=kit&foo=baz'; + }); + + flushSync(() => { + url.searchParams.append('foo', 'qux'); + }); + + flushSync(() => { + url.searchParams.delete('foo'); + }); + + flushSync(() => { + url.searchParams.set('love', 'svelte5'); + }); + + assert.deepEqual(log, [ + 'https://svelte.dev/?foo=bar&t=123', + 'https://svelte.dev/?q=kit&foo=baz', + 'https://svelte.dev/?q=kit&foo=baz&foo=qux', + 'https://svelte.dev/?q=kit', + 'https://svelte.dev/?q=kit&love=svelte5' + ]); + + cleanup(); +});