Skip to content

Commit

Permalink
fix: keep Date objects on setData (#1720)
Browse files Browse the repository at this point in the history
  • Loading branch information
freakzlike committed Aug 15, 2022
1 parent d13e3fa commit 61002d4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/utils.ts
Expand Up @@ -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 {
Expand Down
27 changes: 27 additions & 0 deletions tests/setData.spec.ts
Expand Up @@ -187,4 +187,31 @@ describe('setData', () => {
await wrapper.setData({ state: { items: ['2', '3'] } })
expect(wrapper.html()).toMatchInlineSnapshot(`"<div>2,3</div>"`)
})

it('should keep Date object on setData', async () => {
const wrapper = mount(
{
template: '<div/>',
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')
})
})

0 comments on commit 61002d4

Please sign in to comment.