diff --git a/packages/uploader/index.js b/packages/uploader/index.js index dace19820..b98f70da9 100644 --- a/packages/uploader/index.js +++ b/packages/uploader/index.js @@ -32,6 +32,7 @@ export default sfc({ files = files.length === 1 ? files[0] : [].slice.call(files, 0); if (!files || (this.beforeRead && !this.beforeRead(files))) { + this.resetInput(); return; } @@ -82,7 +83,13 @@ export default sfc({ this.$emit('oversize', files); } else { this.afterRead && this.afterRead(files); - this.$refs.input && (this.$refs.input.value = ''); + } + this.resetInput(); + }, + + resetInput() { + if (this.$refs.input) { + this.$refs.input.value = ''; } } }, diff --git a/packages/uploader/test/index.spec.js b/packages/uploader/test/index.spec.js index 49b65d1bb..9863b08c9 100644 --- a/packages/uploader/test/index.spec.js +++ b/packages/uploader/test/index.spec.js @@ -69,8 +69,11 @@ it('before read return false', () => { } }); + const input = wrapper.find('input'); + wrapper.vm.onChange(file); expect(afterRead.mock.calls.length).toBeFalsy(); + expect(input.element.value).toEqual(''); }); test('file size overlimit', async () => { diff --git a/test/demo-test.js b/test/demo-test.js index 4f8c82db7..348e3bb9f 100644 --- a/test/demo-test.js +++ b/test/demo-test.js @@ -10,8 +10,8 @@ const empty = { Vue.component('demo-block', empty); Vue.component('demo-section', empty); -export default function(Demo) { - test(`renders demo correctly`, () => { +export default function (Demo) { + test('renders demo correctly', () => { if (Demo.i18n) { Locale.add(Demo.i18n); }