fix(ImagePreview): should not emit close event after tapped when using async-close (#5410)

This commit is contained in:
neverland 2019-12-28 08:09:24 +08:00 committed by GitHub
parent 3250804791
commit 93e6c81c49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 7 deletions

View File

@ -118,12 +118,12 @@ export default createComponent({
this.doubleClickTimer = setTimeout(() => {
const index = this.active;
this.$emit('close', {
index,
url: this.images[index]
});
if (!this.asyncClose) {
this.$emit('close', {
index,
url: this.images[index]
});
this.$emit('input', false);
}

View File

@ -36,20 +36,31 @@ test('render image', async () => {
expect(wrapper.emitted('change')[0][0]).toEqual(2);
});
test('async close', () => {
test('async close prop', async () => {
const wrapper = mount(ImagePreviewVue, {
propsData: {
images,
value: true,
asyncClose: true
},
listeners: {
input(value) {
wrapper.setProps({ value });
}
}
});
const swipe = wrapper.find('.van-swipe__track');
// should not emit input or close event when tapped
triggerDrag(swipe, 0, 0);
await later(300);
expect(wrapper.emitted('input')).toBeFalsy();
expect(wrapper.emitted('close')).toBeFalsy();
wrapper.vm.close();
expect(wrapper.emitted('input')[0][0]).toBeFalsy();
expect(wrapper.emitted('input')[0]).toBeTruthy();
expect(wrapper.emitted('close')[0]).toBeTruthy();
});
test('function call', done => {