Skip to content

Commit

Permalink
fix(shared): check dates in looseEqual (vuejs#7940)
Browse files Browse the repository at this point in the history
Fix vuejs#7928
thanks to @w3cj for the initial version. This one is using getTime instead of toUTCString because it
is much faster to compare
  • Loading branch information
posva authored and aJean committed Aug 19, 2020
1 parent 1768cb9 commit 9c630db
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/shared/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ export function looseEqual (a: any, b: any): boolean {
return a.length === b.length && a.every((e, i) => {
return looseEqual(e, b[i])
})
} else if (a instanceof Date && b instanceof Date) {
return a.getTime() === b.getTime()
} else if (!isArrayA && !isArrayB) {
const keysA = Object.keys(a)
const keysB = Object.keys(b)
Expand Down
27 changes: 27 additions & 0 deletions test/unit/features/directives/model-select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,4 +588,31 @@ describe('Directive v-model select', () => {
}).then(done)
})
})

// #7928
it('should correctly handle option with date value', done => {
const vm = new Vue({
data: {
dates: [
new Date(1520000000000),
new Date(1522000000000),
new Date(1516000000000)
],
selectedDate: null
},
template:
'<div>' +
'<select v-model="selectedDate">' +
'<option v-for="(date, i) in dates" :key="i" :value="date">' +
'{{date}}' +
'</option>' +
'</select>' +
'</div>'
}).$mount()

vm.selectedDate = vm.dates[2]
waitForUpdate(() => {
expect(vm.$el.firstChild.selectedIndex).toBe(2)
}).then(done)
})
})

0 comments on commit 9c630db

Please sign in to comment.