fix(ImagePreview): onClose should only trigger once (#5341)
This commit is contained in:
@@ -54,6 +54,7 @@ const ImagePreview = (images, startPosition = 0) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (options.onClose) {
|
if (options.onClose) {
|
||||||
|
instance.$off('close');
|
||||||
instance.$once('close', options.onClose);
|
instance.$once('close', options.onClose);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -102,6 +102,26 @@ test('onClose option', async done => {
|
|||||||
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 => {
|
test('onChange option', async done => {
|
||||||
const instance = ImagePreview({
|
const instance = ImagePreview({
|
||||||
images,
|
images,
|
||||||
|
|||||||
Reference in New Issue
Block a user