From 06e158e20e411934fc3ad58c39e319ac9f9b59c0 Mon Sep 17 00:00:00 2001 From: mengxiong10 <15623530290@163.com> Date: Mon, 11 Nov 2019 10:42:50 +0800 Subject: [PATCH] fix: clear event not triggering (#369) --- __test__/date-picker.test.js | 19 ++++++++++++++++++- src/date-picker.vue | 1 + 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/__test__/date-picker.test.js b/__test__/date-picker.test.js index ec14be1..06114e4 100644 --- a/__test__/date-picker.test.js +++ b/__test__/date-picker.test.js @@ -176,7 +176,12 @@ describe('DatePicker', () => { expect(vm.text).toBe('2019/10/20'); vm.emitValue(emitValue); const emitted = wrapper.emitted(); - expect(emitted.input).toEqual([[emitValue], ['2019/10/22'], [emitValue.getTime()], ['22/10/2019']]); + expect(emitted.input).toEqual([ + [emitValue], + ['2019/10/22'], + [emitValue.getTime()], + ['22/10/2019'], + ]); }); it('prop: shortcut', () => { @@ -269,4 +274,16 @@ describe('DatePicker', () => { const popup = wrapper.find('.mx-datepicker-popup'); expect(popup.element.parentNode).toBe(document.body); }); + + it('feat: should emit clear event when click clear button', () => { + wrapper = shallowMount(DatePicker, { + propsData: { + value: new Date(2019, 10, 9), + }, + }); + const clearButton = wrapper.find('.mx-icon-clear'); + clearButton.trigger('mousedown'); + const emitted = wrapper.emitted(); + expect(emitted.clear).toBeTruthy(); + }); }); diff --git a/src/date-picker.vue b/src/date-picker.vue index 00931ba..c4fca0c 100644 --- a/src/date-picker.vue +++ b/src/date-picker.vue @@ -364,6 +364,7 @@ export default { }, handleClear() { this.emitValue(null); + this.$emit('clear'); }, handleConfirmDate() { const value = this.emitValue(this.currentValue);