fix(ImagePreview): onClose should only trigger once (#5341)

This commit is contained in:
neverland 2019-12-20 20:39:29 +08:00 committed by GitHub
parent 8cb653afc7
commit 5389bcf4fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -54,6 +54,7 @@ const ImagePreview = (images, startPosition = 0) => {
});
if (options.onClose) {
instance.$off('close');
instance.$once('close', options.onClose);
}

View File

@ -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,