mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-05-22 14:39:16 +08:00
fix(ImagePreview): onClose should only trigger once (#5341)
This commit is contained in:
parent
8cb653afc7
commit
5389bcf4fb
@ -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,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user