diff --git a/src/image-preview/ImagePreview.js b/src/image-preview/ImagePreview.js index f15c69212..1409c0519 100644 --- a/src/image-preview/ImagePreview.js +++ b/src/image-preview/ImagePreview.js @@ -118,12 +118,12 @@ export default createComponent({ this.doubleClickTimer = setTimeout(() => { const index = this.active; - this.$emit('close', { - index, - url: this.images[index] - }); - if (!this.asyncClose) { + this.$emit('close', { + index, + url: this.images[index] + }); + this.$emit('input', false); } diff --git a/src/image-preview/test/index.spec.js b/src/image-preview/test/index.spec.js index 93c144bd7..0b4065c3e 100644 --- a/src/image-preview/test/index.spec.js +++ b/src/image-preview/test/index.spec.js @@ -36,20 +36,31 @@ test('render image', async () => { expect(wrapper.emitted('change')[0][0]).toEqual(2); }); -test('async close', () => { +test('async close prop', async () => { const wrapper = mount(ImagePreviewVue, { propsData: { images, value: true, asyncClose: true + }, + listeners: { + input(value) { + wrapper.setProps({ value }); + } } }); const swipe = wrapper.find('.van-swipe__track'); + + // should not emit input or close event when tapped triggerDrag(swipe, 0, 0); + await later(300); expect(wrapper.emitted('input')).toBeFalsy(); + expect(wrapper.emitted('close')).toBeFalsy(); + wrapper.vm.close(); - expect(wrapper.emitted('input')[0][0]).toBeFalsy(); + expect(wrapper.emitted('input')[0]).toBeTruthy(); + expect(wrapper.emitted('close')[0]).toBeTruthy(); }); test('function call', done => {