improved tests

pull/11504/head
godzylinux 2 years ago committed by FoHoOV
parent 65c006490f
commit c48f6ff03e

@ -610,10 +610,10 @@ test('date fine grained tests', () => {
}; };
const cleanup = effect_root(() => { const cleanup = effect_root(() => {
for (const key of Object.keys(date)) { for (const key of Object.keys(changes)) {
render_effect(() => { render_effect(() => {
date[key](); date[key]();
assert.equal(changes[key], true, test_description); assert.equal(changes[key], true, `${test_description}: for ${key}`);
}); });
} }
}); });
@ -625,9 +625,13 @@ test('date fine grained tests', () => {
getFullYear: true, getFullYear: true,
getUTCFullYear: true, getUTCFullYear: true,
getDate: true, getDate: true,
getUTCDate: true getUTCDate: true,
getMonth: true,
getUTCMonth: true,
getDay: true,
getUTCDay: true
}; };
test_description = 'changing full that will cause month change as well'; test_description = 'changing setFullYear that will cause month/day change as well';
date.setFullYear(initial_date.getFullYear() + 1, initial_date.getMonth() + 1); date.setFullYear(initial_date.getFullYear() + 1, initial_date.getMonth() + 1);
}); });
@ -645,11 +649,11 @@ test('date fine grained tests', () => {
getUTCMinutes: true, getUTCMinutes: true,
getSeconds: true, getSeconds: true,
getUTCSeconds: true, getUTCSeconds: true,
getMilliSeconds: true, getMilliseconds: true,
getUTCMilliSeconds: true getUTCMilliseconds: true
}; };
test_description = 'changing seconds that will change day/hour/minutes/seconds/milliseconds'; test_description = 'changing seconds that will change day/hour/minutes/seconds/milliseconds';
date.setSeconds(60 * 60 * 25, 10); date.setSeconds(60 * 60 * 25 + 1, 10);
}); });
flushSync(() => { flushSync(() => {
@ -658,8 +662,10 @@ test('date fine grained tests', () => {
...changes, ...changes,
getMonth: true, getMonth: true,
getUTCMonth: true, getUTCMonth: true,
getMilliSeconds: true, getDay: true,
getUTCMilliSeconds: true getUTCDay: true,
getMilliseconds: true,
getUTCMilliseconds: true
}; };
test_description = 'changing month'; test_description = 'changing month';
date.setMonth(date.getMonth() + 1); date.setMonth(date.getMonth() + 1);

@ -114,7 +114,7 @@ test('url.href', () => {
test('url fine grained tests', () => { test('url fine grained tests', () => {
const url = new ReactiveURL('https://svelte.dev/'); const url = new ReactiveURL('https://svelte.dev/');
let changes: Record<keyof typeof url, boolean> = { let changes: Record<string, boolean> = {
hash: true, hash: true,
host: true, host: true,
hostname: true, hostname: true,
@ -126,9 +126,7 @@ test('url fine grained tests', () => {
port: true, port: true,
protocol: true, protocol: true,
search: true, search: true,
searchParams: true, searchParams: true
toJSON: true,
toString: true
}; };
let test_description: string = ''; let test_description: string = '';
@ -139,39 +137,19 @@ test('url fine grained tests', () => {
}; };
const cleanup = effect_root(() => { const cleanup = effect_root(() => {
render_effect(() => { for (const key of Object.keys(changes) as Array<keyof typeof url>) {
url.hash; if (key === 'searchParams') {
assert.equal(changes.hash, true, test_description); continue;
}); }
render_effect(() => {
render_effect(() => { url[key];
url.host; assert.equal(changes[key], true, `${test_description}: for ${key}`);
assert.equal(changes.host, true, test_description); });
}); }
render_effect(() => {
url.hostname;
assert.equal(changes.hostname, true, test_description);
});
render_effect(() => {
url.href;
assert.equal(changes.href, true, test_description);
});
render_effect(() => {
url.origin;
assert.equal(changes.origin, true, test_description);
});
render_effect(() => {
url.search;
assert.equal(changes.search, true, test_description);
});
render_effect(() => { render_effect(() => {
url.searchParams.get('fohoov'); url.searchParams.get('fohoov');
assert.equal(changes.searchParams, true, test_description); assert.equal(changes.searchParams, true, `${test_description}: for searchParams`);
}); });
}); });
@ -184,7 +162,7 @@ test('url fine grained tests', () => {
flushSync(() => { flushSync(() => {
reset_change(); reset_change();
changes = { ...changes, origin: true, href: true }; changes = { ...changes, protocol: true, origin: true, href: true };
test_description = 'changing protocol'; test_description = 'changing protocol';
url.protocol = 'http'; url.protocol = 'http';
}); });

Loading…
Cancel
Save