Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(shared): check dates in looseEqual #7940

Merged
merged 1 commit into from
Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/shared/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,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)
})
})