Skip to content

Commit caf8f2d

Browse files
committed
fixed url tests
1 parent e64bbd7 commit caf8f2d

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
lines changed

packages/svelte/src/reactivity/url.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ export const ReactiveURL = make_reactive(URLWithReactiveSearchParams, {
220220
if (options.value.search === add_character_if_not_exists(params[0], '?', 'prepend')) {
221221
return false;
222222
}
223-
options.notify_read_properties(['href', 'hash', 'search']);
223+
options.notify_read_properties(['href', 'search']);
224224
return true;
225225
},
226226
href: (options, ...params) => {

packages/svelte/src/reactivity/url.test.ts

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ test('url fine grained tests', () => {
130130
toJSON: true,
131131
toString: true
132132
};
133+
let test_description: string = '';
133134

134135
const reset_change = () => {
135136
for (const key of Object.keys(changes) as Array<keyof typeof url>) {
@@ -140,93 +141,110 @@ test('url fine grained tests', () => {
140141
const cleanup = effect_root(() => {
141142
render_effect(() => {
142143
url.hash;
143-
assert.equal(changes.hash, true);
144+
assert.equal(changes.hash, true, test_description);
144145
});
145146

146147
render_effect(() => {
147148
url.host;
148-
assert.equal(changes.host, true);
149+
assert.equal(changes.host, true, test_description);
149150
});
150151

151152
render_effect(() => {
152153
url.hostname;
153-
assert.equal(changes.hostname, true);
154+
assert.equal(changes.hostname, true, test_description);
154155
});
155156

156157
render_effect(() => {
157158
url.href;
158-
assert.equal(changes.href, true);
159+
assert.equal(changes.href, true, test_description);
159160
});
160161

161162
render_effect(() => {
162163
url.origin;
163-
assert.equal(changes.origin, true);
164+
assert.equal(changes.origin, true, test_description);
164165
});
165166

166167
render_effect(() => {
167168
url.search;
168-
assert.equal(changes.search, true);
169+
assert.equal(changes.search, true, test_description);
169170
});
170171

171172
render_effect(() => {
172173
url.searchParams.get('fohoov');
173-
assert.equal(changes.searchParams, true);
174-
});
175-
176-
render_effect(() => {
177-
url;
178-
reset_change();
174+
assert.equal(changes.searchParams, true, test_description);
179175
});
180176
});
181177

182178
flushSync(() => {
179+
reset_change();
183180
changes = { ...changes, origin: true, host: true, pathname: true, href: true };
181+
test_description = 'changing href';
184182
url.href = 'https://www.google.com/test';
185183
});
186184

187185
flushSync(() => {
186+
reset_change();
188187
changes = { ...changes, origin: true, href: true };
188+
test_description = 'changing protocol';
189189
url.protocol = 'http';
190190
});
191191

192192
flushSync(() => {
193+
reset_change();
194+
test_description = 'changing protocol to same thing';
193195
url.protocol = 'http';
194196
});
195197

196198
flushSync(() => {
199+
reset_change();
197200
changes = { ...changes, hash: true, href: true };
201+
test_description = 'changing hash';
198202
url.hash = 'new-hash';
199203
});
200204

201205
flushSync(() => {
206+
reset_change();
207+
test_description = 'changing hash to same thing';
202208
url.hash = 'new-hash';
203209
});
204210

205211
flushSync(() => {
206-
changes = { ...changes, hostname: true, href: true };
212+
reset_change();
213+
changes = { ...changes, hostname: true, host: true, href: true };
214+
test_description = 'changing hostname';
207215
url.hostname = 'fohoov';
208216
});
209217

210218
flushSync(() => {
211-
changes = { ...changes, search: true, searchParams: true };
219+
reset_change();
220+
changes = { ...changes, href: true, search: true, searchParams: true };
221+
test_description = 'changing search';
212222
url.search = 'fohoov=true';
213223
});
214224

215225
flushSync(() => {
226+
reset_change();
227+
test_description = 'changing search to same thing';
216228
url.search = 'fohoov=true';
217229
});
218230

219231
flushSync(() => {
220-
changes = { ...changes, search: true, searchParams: true };
232+
reset_change();
233+
changes = { ...changes, href: true, search: true, searchParams: true };
234+
test_description = 'changing search param to false';
221235
url.search = 'fohoov=false';
222236
});
223237

224238
flushSync(() => {
225-
changes = { ...changes, search: true, searchParams: true };
239+
reset_change();
240+
changes = { ...changes, href: true, search: true, searchParams: true };
241+
test_description = 'clearing search';
226242
url.search = '';
227243
});
228244

229245
flushSync(() => {
246+
reset_change();
247+
test_description = 'clearing search again (expects no change)';
230248
url.search = '';
231249
});
232250

0 commit comments

Comments
 (0)