|
|
|
|
@ -4,7 +4,7 @@ import { SvelteURL } from './url.js';
|
|
|
|
|
import { assert, test } from 'vitest';
|
|
|
|
|
|
|
|
|
|
test('url.hash', () => {
|
|
|
|
|
const url = new SvelteURL('http://google.com');
|
|
|
|
|
const url = new SvelteURL('https://svelte.dev');
|
|
|
|
|
const log: any = [];
|
|
|
|
|
|
|
|
|
|
const cleanup = effect_root(() => {
|
|
|
|
|
@ -18,7 +18,7 @@ test('url.hash', () => {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
flushSync(() => {
|
|
|
|
|
url.href = 'http://google.com/a/b/c#def';
|
|
|
|
|
url.href = 'https://svelte.dev/a/b/c#def';
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
flushSync(() => {
|
|
|
|
|
@ -31,6 +31,44 @@ test('url.hash', () => {
|
|
|
|
|
cleanup();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('url.href', () => {
|
|
|
|
|
const url = new SvelteURL('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(() => {
|
|
|
|
|
// changes from searchParams should be synced to URL instance as well
|
|
|
|
|
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();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('url.searchParams', () => {
|
|
|
|
|
const url = new SvelteURL('https://svelte.dev?foo=bar&t=123');
|
|
|
|
|
const log: any = [];
|
|
|
|
|
@ -76,3 +114,7 @@ test('url.searchParams', () => {
|
|
|
|
|
|
|
|
|
|
cleanup();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('URL.instanceOf', () => {
|
|
|
|
|
assert.equal(new SvelteURL('https://svelte.dev') instanceof URL, true);
|
|
|
|
|
});
|
|
|
|
|
|