fix(ImagePreview): close-on-popstate not work #7880

This commit is contained in:
chenjiahan
2021-01-10 18:59:24 +08:00
parent 4c4d303363
commit 0f7c088f9f
3 changed files with 32 additions and 22 deletions
-21
View File
@@ -223,27 +223,6 @@ test('zoom out', async () => {
restore();
});
test('closeOnPopstate', () => {
const wrapper = mount(ImagePreviewVue, {
props: {
images,
value: true,
closeOnPopstate: true,
},
});
trigger(window, 'popstate');
expect(wrapper.emitted('input')[0][0]).toBeFalsy();
wrapper.setProps({
value: true,
closeOnPopstate: false,
});
trigger(window, 'popstate');
expect(wrapper.emitted('input')[1]).toBeFalsy();
});
test('get container with function call ', async (done) => {
const element = document.createElement('div');
document.body.appendChild(element);
+26
View File
@@ -1,6 +1,7 @@
import { mount } from '@vue/test-utils';
import ImagePreviewComponent from '../ImagePreview';
import { later } from '../../../test';
import { trigger } from '../../utils';
const images = [
'https://img.yzcdn.cn/1.png',
@@ -112,3 +113,28 @@ test('should hide index when show-index prop is false', async () => {
await wrapper.setProps({ showIndex: false });
expect(wrapper.find('.van-image-preview__index').exists()).toBeFalsy();
});
test('should hide ImagePreview after popstate', async () => {
const wrapper = mount(ImagePreviewComponent, {
props: {
images,
show: true,
},
});
trigger(window, 'popstate');
expect(wrapper.emitted('update:show')[0][0]).toBeFalsy();
});
test('should not hide ImagePreview after popstate when close-on-popstate is false', async () => {
const wrapper = mount(ImagePreviewComponent, {
props: {
images,
show: true,
closeOnPopstate: false,
},
});
trigger(window, 'popstate');
expect(wrapper.emitted('update:show')).toBeFalsy();
});