fix(ImagePreview): close event triggered twice (#5411)

This commit is contained in:
neverland
2019-12-28 08:43:57 +08:00
committed by GitHub
parent 93e6c81c49
commit 8dea26db95
11 changed files with 234 additions and 254 deletions
+2 -29
View File
@@ -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 => {