diff --git a/src/calendar.vue b/src/calendar.vue index 0caeff7..2a14620 100644 --- a/src/calendar.vue +++ b/src/calendar.vue @@ -258,12 +258,16 @@ export default { return date.getTime() }, inBefore (time, startAt) { - startAt = startAt || this.startAt + if (startAt === undefined) { + startAt = this.startAt + } return (this.notBeforeTime && time < this.notBeforeTime) || (startAt && time < this.getCriticalTime(startAt)) }, inAfter (time, endAt) { - endAt = endAt || this.endAt + if (endAt === undefined) { + endAt = this.endAt + } return (this.notAfterTime && time > this.notAfterTime) || (endAt && time > this.getCriticalTime(endAt)) }, diff --git a/test/index.spec.js b/test/index.spec.js index 0b2b7cb..db46fde 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -247,24 +247,43 @@ describe('datepicker', () => { input.trigger('input') input.trigger('change') const expectDate = new Date(2018, 8, 10) - wrapper.setProps({ - range: true - }) Vue.nextTick(() => { - input.setValue('2018-09-10 ~ 2018-09-11') - input.trigger('input') - input.trigger('change') - const expectRange = [new Date(2018, 8, 10), new Date(2018, 8, 11)] - input.setValue('2018-09-10 ~ 2018-08-10') - input.trigger('input') - input.trigger('change') const emitted = wrapper.emitted() - expect(emitted.input).toEqual([[expectDate], [expectRange]]) - expect(emitted['input-error']).toEqual([['2018-09-10 ~ 2018-08-10']]) + expect(emitted.input).toEqual([[expectDate]]) done() }) }) + it('type range input should be right', (done) => { + wrapper = mount(DatePicker, { + propsData: { + format: 'YYYY-MM-DD', + range: true + }, + sync: false + }) + const input = wrapper.find('input') + input.setValue('2018-09-10 ~ 2018-09-11') + input.trigger('change') + const expectRange = [new Date(2018, 8, 10), new Date(2018, 8, 11)] + Vue.nextTick(() => { + input.setValue('2018-09-09 ~ 2018-09-12') + input.trigger('input') + input.trigger('change') + const expectRange2 = [new Date(2018, 8, 9), new Date(2018, 8, 12)] + Vue.nextTick(() => { + input.setValue('2018-09-10 ~ 2018-08-10') + input.trigger('input') + input.trigger('change') + const expectError = '2018-09-10 ~ 2018-08-10' + const emitted = wrapper.emitted() + expect(emitted.input).toEqual([[expectRange], [expectRange2]]) + expect(emitted['input-error']).toEqual([[expectError]]) + done() + }) + }) + }) + it('prop: dateFormat', () => { wrapper = mount(DatePicker, { propsData: {