diff --git a/src/utils.ts b/src/utils.ts index f27368f40..23c10ea61 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -74,6 +74,8 @@ export const mergeDeep = ( if (Array.isArray(targetValue) && Array.isArray(sourceValue)) { target[key] = sourceValue + } else if (sourceValue instanceof Date) { + target[key] = sourceValue } else if (isObject(targetValue) && isObject(sourceValue)) { target[key] = mergeDeep(Object.assign({}, targetValue), sourceValue) } else { diff --git a/tests/setData.spec.ts b/tests/setData.spec.ts index 9d291eaf9..30cfabd55 100644 --- a/tests/setData.spec.ts +++ b/tests/setData.spec.ts @@ -187,4 +187,31 @@ describe('setData', () => { await wrapper.setData({ state: { items: ['2', '3'] } }) expect(wrapper.html()).toMatchInlineSnapshot(`"
2,3
"`) }) + + it('should keep Date object on setData', async () => { + const wrapper = mount( + { + template: '
', + props: { modelValue: Date }, + data() { + return { value: this.modelValue } + } + }, + { + props: { + modelValue: new Date('2022-08-10T12:15:54Z') + } + } + ) + + expect(wrapper.vm.value).toBeInstanceOf(Date) + expect(wrapper.vm.value!.toISOString()).toBe('2022-08-10T12:15:54.000Z') + + await wrapper.setData({ + value: new Date('2022-08-11T12:15:54Z') + }) + + expect(wrapper.vm.value).toBeInstanceOf(Date) + expect(wrapper.vm.value!.toISOString()).toBe('2022-08-11T12:15:54.000Z') + }) })