fix(Popup): close event emiited twice (#10132)

This commit is contained in:
neverland 2021-12-30 21:15:42 +08:00 committed by GitHub
parent 9c16f4240a
commit 7831553bee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 3 deletions

View File

@ -213,10 +213,11 @@ export default defineComponent({
watch( watch(
() => props.show, () => props.show,
(value) => { (show) => {
if (value) { if (show && !opened) {
open(); open();
} else { }
if (!show && opened) {
opened = false; opened = false;
emit('close'); emit('close');
} }

View File

@ -129,6 +129,22 @@ test('should emit close event when show prop is set to false', async () => {
expect(onClose).toHaveBeenCalledTimes(1); expect(onClose).toHaveBeenCalledTimes(1);
}); });
test('should emit close event after clicking the overlay', async () => {
const onClose = jest.fn();
wrapper = mount(Popup, {
props: {
show: true,
onClose,
'onUpdate:show': (show) => {
wrapper.setProps({ show });
},
},
});
await wrapper.find('.van-overlay').trigger('click');
expect(onClose).toHaveBeenCalledTimes(1);
});
test('should change duration when using duration prop', () => { test('should change duration when using duration prop', () => {
wrapper = mount(Popup, { wrapper = mount(Popup, {
props: { props: {