diff --git a/src/image-preview/index.js b/src/image-preview/index.js index 08742fe30..74101998a 100644 --- a/src/image-preview/index.js +++ b/src/image-preview/index.js @@ -54,6 +54,7 @@ const ImagePreview = (images, startPosition = 0) => { }); if (options.onClose) { + instance.$off('close'); instance.$once('close', options.onClose); } diff --git a/src/image-preview/test/index.spec.js b/src/image-preview/test/index.spec.js index 727970b0c..93c144bd7 100644 --- a/src/image-preview/test/index.spec.js +++ b/src/image-preview/test/index.spec.js @@ -102,6 +102,26 @@ test('onClose option', async done => { done(); }); +test('onClose should only trigger once', async done => { + const onClose = jest.fn(); + const instance = ImagePreview({ + images, + startPostion: 1, + onClose + }); + + ImagePreview({ + images, + startPostion: 1, + onClose + }); + + instance.close(); + + expect(onClose).toHaveBeenCalledTimes(1); + done(); +}); + test('onChange option', async done => { const instance = ImagePreview({ images,