Skip to content

Commit

Permalink
fix(shared): check dates in looseEqual (#7940)
Browse files Browse the repository at this point in the history
Fix #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 yyx990803 committed Oct 24, 2018
1 parent 7597bb0 commit db7287c
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 db7287c

Please sign in to comment.