Skip to content

Commit 7994576

Browse files
committed
improved tests
1 parent aea4d65 commit 7994576

File tree

2 files changed

+28
-44
lines changed

2 files changed

+28
-44
lines changed

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -610,10 +610,10 @@ test('date fine grained tests', () => {
610610
};
611611

612612
const cleanup = effect_root(() => {
613-
for (const key of Object.keys(date)) {
613+
for (const key of Object.keys(changes)) {
614614
render_effect(() => {
615615
date[key]();
616-
assert.equal(changes[key], true, test_description);
616+
assert.equal(changes[key], true, `${test_description}: for ${key}`);
617617
});
618618
}
619619
});
@@ -625,9 +625,13 @@ test('date fine grained tests', () => {
625625
getFullYear: true,
626626
getUTCFullYear: true,
627627
getDate: true,
628-
getUTCDate: true
628+
getUTCDate: true,
629+
getMonth: true,
630+
getUTCMonth: true,
631+
getDay: true,
632+
getUTCDay: true
629633
};
630-
test_description = 'changing full that will cause month change as well';
634+
test_description = 'changing setFullYear that will cause month/day change as well';
631635
date.setFullYear(initial_date.getFullYear() + 1, initial_date.getMonth() + 1);
632636
});
633637

@@ -645,11 +649,11 @@ test('date fine grained tests', () => {
645649
getUTCMinutes: true,
646650
getSeconds: true,
647651
getUTCSeconds: true,
648-
getMilliSeconds: true,
649-
getUTCMilliSeconds: true
652+
getMilliseconds: true,
653+
getUTCMilliseconds: true
650654
};
651655
test_description = 'changing seconds that will change day/hour/minutes/seconds/milliseconds';
652-
date.setSeconds(60 * 60 * 25, 10);
656+
date.setSeconds(60 * 60 * 25 + 1, 10);
653657
});
654658

655659
flushSync(() => {
@@ -658,8 +662,10 @@ test('date fine grained tests', () => {
658662
...changes,
659663
getMonth: true,
660664
getUTCMonth: true,
661-
getMilliSeconds: true,
662-
getUTCMilliSeconds: true
665+
getDay: true,
666+
getUTCDay: true,
667+
getMilliseconds: true,
668+
getUTCMilliseconds: true
663669
};
664670
test_description = 'changing month';
665671
date.setMonth(date.getMonth() + 1);

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

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ test('url.href', () => {
114114
test('url fine grained tests', () => {
115115
const url = new ReactiveURL('https://svelte.dev/');
116116

117-
let changes: Record<keyof typeof url, boolean> = {
117+
let changes: Record<string, boolean> = {
118118
hash: true,
119119
host: true,
120120
hostname: true,
@@ -126,9 +126,7 @@ test('url fine grained tests', () => {
126126
port: true,
127127
protocol: true,
128128
search: true,
129-
searchParams: true,
130-
toJSON: true,
131-
toString: true
129+
searchParams: true
132130
};
133131
let test_description: string = '';
134132

@@ -139,39 +137,19 @@ test('url fine grained tests', () => {
139137
};
140138

141139
const cleanup = effect_root(() => {
142-
render_effect(() => {
143-
url.hash;
144-
assert.equal(changes.hash, true, test_description);
145-
});
146-
147-
render_effect(() => {
148-
url.host;
149-
assert.equal(changes.host, true, test_description);
150-
});
151-
152-
render_effect(() => {
153-
url.hostname;
154-
assert.equal(changes.hostname, true, test_description);
155-
});
156-
157-
render_effect(() => {
158-
url.href;
159-
assert.equal(changes.href, true, test_description);
160-
});
161-
162-
render_effect(() => {
163-
url.origin;
164-
assert.equal(changes.origin, true, test_description);
165-
});
166-
167-
render_effect(() => {
168-
url.search;
169-
assert.equal(changes.search, true, test_description);
170-
});
140+
for (const key of Object.keys(changes) as Array<keyof typeof url>) {
141+
if (key === 'searchParams') {
142+
continue;
143+
}
144+
render_effect(() => {
145+
url[key];
146+
assert.equal(changes[key], true, `${test_description}: for ${key}`);
147+
});
148+
}
171149

172150
render_effect(() => {
173151
url.searchParams.get('fohoov');
174-
assert.equal(changes.searchParams, true, test_description);
152+
assert.equal(changes.searchParams, true, `${test_description}: for searchParams`);
175153
});
176154
});
177155

@@ -184,7 +162,7 @@ test('url fine grained tests', () => {
184162

185163
flushSync(() => {
186164
reset_change();
187-
changes = { ...changes, origin: true, href: true };
165+
changes = { ...changes, protocol: true, origin: true, href: true };
188166
test_description = 'changing protocol';
189167
url.protocol = 'http';
190168
});

0 commit comments

Comments
 (0)