Skip to content

Commit f1285d3

Browse files
committed
improved date tests
1 parent caf8f2d commit f1285d3

File tree

1 file changed

+87
-1
lines changed

1 file changed

+87
-1
lines changed

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

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ test('date.setSeconds - edge cases', () => {
551551
cleanup();
552552
});
553553

554-
test('ReactiveDate propagated changes', () => {
554+
test('Date propagated changes', () => {
555555
const date = new ReactiveDate(initial_date);
556556
const log: any = [];
557557

@@ -582,6 +582,92 @@ test('ReactiveDate propagated changes', () => {
582582
cleanup();
583583
});
584584

585+
test('date fine grained tests', () => {
586+
const date = new ReactiveDate(initial_date);
587+
588+
let changes: Record<string, boolean> = {
589+
getFullYear: true,
590+
getUTCFullYear: true,
591+
getMonth: true,
592+
getUTCMonth: true,
593+
getDate: true,
594+
getUTCDate: true,
595+
getDay: true,
596+
getUTCDay: true,
597+
getHours: true,
598+
getUTCHours: true,
599+
getMinutes: true,
600+
getUTCMinutes: true,
601+
getMilliseconds: true,
602+
getUTCMilliseconds: true
603+
};
604+
let test_description: string = '';
605+
606+
const reset_change = () => {
607+
for (const key of Object.keys(changes)) {
608+
changes[key] = false;
609+
}
610+
};
611+
612+
const cleanup = effect_root(() => {
613+
for (const key of Object.keys(date)) {
614+
render_effect(() => {
615+
date[key]();
616+
assert.equal(changes[key], true, test_description);
617+
});
618+
}
619+
});
620+
621+
flushSync(() => {
622+
reset_change();
623+
changes = {
624+
...changes,
625+
getFullYear: true,
626+
getUTCFullYear: true,
627+
getDate: true,
628+
getUTCDate: true
629+
};
630+
test_description = 'changing full that will cause month change as well';
631+
date.setFullYear(initial_date.getFullYear() + 1, initial_date.getMonth() + 1);
632+
});
633+
634+
flushSync(() => {
635+
reset_change();
636+
changes = {
637+
...changes,
638+
getDate: true,
639+
getUTCDate: true,
640+
getDay: true,
641+
getUTCDay: true,
642+
getHours: true,
643+
getUTCHours: true,
644+
getMinutes: true,
645+
getUTCMinutes: true,
646+
getSeconds: true,
647+
getUTCSeconds: true,
648+
getMilliSeconds: true,
649+
getUTCMilliSeconds: true
650+
};
651+
test_description = 'changing seconds that will change day/hour/minutes/seconds/milliseconds';
652+
date.setSeconds(60 * 60 * 25, 10);
653+
});
654+
655+
flushSync(() => {
656+
reset_change();
657+
changes = {
658+
...changes,
659+
getMonth: true,
660+
getUTCMonth: true,
661+
getMilliSeconds: true,
662+
getUTCMilliSeconds: true
663+
};
664+
test_description = 'changing month';
665+
date.setMonth(date.getMonth() + 1);
666+
});
667+
668+
cleanup();
669+
});
670+
585671
test('Date.instanceOf', () => {
586672
assert.equal(new ReactiveDate() instanceof Date, true);
587673
});

0 commit comments

Comments
 (0)