fix(ImagePreview): close event triggered twice (#5411)
This commit is contained in:
@@ -92,7 +92,7 @@ test('double click', async done => {
|
||||
done();
|
||||
});
|
||||
|
||||
test('onClose option', async done => {
|
||||
test('onClose option', () => {
|
||||
const onClose = jest.fn();
|
||||
const instance = ImagePreview({
|
||||
images,
|
||||
@@ -100,37 +100,10 @@ test('onClose option', async done => {
|
||||
onClose
|
||||
});
|
||||
|
||||
instance.$emit('input', true);
|
||||
expect(onClose).toHaveBeenCalledTimes(0);
|
||||
|
||||
await later(300);
|
||||
|
||||
const wrapper = document.querySelector('.van-image-preview');
|
||||
const swipe = wrapper.querySelector('.van-swipe__track');
|
||||
triggerDrag(swipe, 0, 0);
|
||||
expect(onClose).toHaveBeenCalledTimes(1);
|
||||
expect(onClose).toHaveBeenCalledWith({ index: 0, url: 'https://img.yzcdn.cn/1.png' });
|
||||
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();
|
||||
expect(onClose).toHaveBeenCalledWith({ index: 0, url: 'https://img.yzcdn.cn/1.png' });
|
||||
});
|
||||
|
||||
test('onChange option', async done => {
|
||||
|
||||
Reference in New Issue
Block a user