fix: consider `valueOf` in the reactive methods of `SvelteDate` (#14227)

pull/14207/head
Paolo Ricciuti 2 months ago committed by GitHub
parent f0c2d4c698
commit 1060bea6e1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: consider `valueOf` in the reactive methods of `SvelteDate`

@ -30,7 +30,7 @@ export class SvelteDate extends Date {
);
for (const method of methods) {
if (method.startsWith('get') || method.startsWith('to')) {
if (method.startsWith('get') || method.startsWith('to') || method === 'valueOf') {
// @ts-ignore
proto[method] = function (...args) {
// don't memoize if there are arguments

@ -588,6 +588,30 @@ test('Date.toLocaleString', () => {
cleanup();
});
test('Date.valueOf', () => {
const date = new SvelteDate(initial_date);
const log: any = [];
const cleanup = effect_root(() => {
render_effect(() => {
log.push(date.valueOf());
});
});
flushSync();
assert.deepEqual(log, [initial_date.valueOf()]);
flushSync(() => {
date.setTime(date.getTime() + 10);
});
assert.deepEqual(log, [initial_date.valueOf(), new Date(initial_date.getTime() + 10).valueOf()]);
cleanup();
});
test('Date.instanceOf', () => {
assert.equal(new SvelteDate() instanceof Date, true);
});

Loading…
Cancel
Save