diff --git a/packages/dialog/__tests__/dialog.spec.ts b/packages/dialog/__tests__/dialog.spec.ts index b5ae7c7fc8..3f02671e68 100644 --- a/packages/dialog/__tests__/dialog.spec.ts +++ b/packages/dialog/__tests__/dialog.spec.ts @@ -230,5 +230,32 @@ describe('Dialog.vue', () => { await nextTick() expect(wrapper.find('.el-dialog__body').exists()).toBe(false) }) + + test('should emit close event', async () => { + let visible = true + const onClose = jest.fn() + const onClosed = jest.fn() + const wrapper = _mount({ + props: { + modelValue: visible, + 'onUpdate:modelValue': (val: boolean) => visible = val, + onClose, + onClosed, + }, + }) + + expect(wrapper.vm.visible).toBe(true) + await nextTick() + await rAF() + await nextTick() + + await wrapper.find('.el-overlay').trigger('click') + await nextTick() + await rAF() + await nextTick() + expect(onClose).toHaveBeenCalled() + expect(onClosed).toHaveBeenCalled() + expect(visible).toBe(false) + }) }) }) diff --git a/packages/dialog/src/index.vue b/packages/dialog/src/index.vue index 6440a96739..c9236e9bab 100644 --- a/packages/dialog/src/index.vue +++ b/packages/dialog/src/index.vue @@ -4,6 +4,7 @@ name="dialog-fade" @after-enter="afterEnter" @after-leave="afterLeave" + @before-leave="beforeLeave" > { }) test('should open and close drawer properly', async () => { + const onClose = jest.fn() + const onClosed = jest.fn() + const onOpened = jest.fn() const wrapper = _mount( ` - + ${content} `, @@ -98,18 +101,34 @@ describe('Drawer', () => { title, visible: false, }), + { + methods: { + onOpened, + onClose, + onClosed, + }, + }, ) const vm = wrapper.vm as any await nextTick() await rAF() await nextTick() + expect(onOpened).not.toHaveBeenCalled() const drawerEl = wrapper.find('.el-overlay').element as HTMLDivElement expect(drawerEl.style.display).toEqual('none') vm.visible = true await nextTick() + await rAF() expect(drawerEl.style.display).not.toEqual('none') + expect(onOpened).toHaveBeenCalled() + + // vm.visible = false + // await nextTick() + // await rAF() + // await nextTick() + // expect(onClose).toHaveBeenCalled() }) test('should destroy every child after drawer was closed when destroy-on-close flag is true', async () => { diff --git a/packages/drawer/src/index.vue b/packages/drawer/src/index.vue index 1422091309..6ebdd4d95f 100644 --- a/packages/drawer/src/index.vue +++ b/packages/drawer/src/index.vue @@ -4,6 +4,7 @@ name="el-drawer-fade" @after-enter="afterEnter" @after-leave="afterLeave" + @before-leave="beforeLeave" > { mask: false, }) expect(wrapper.find(selector).exists()).toBe(false) + await wrapper.setProps({ + mask: true, + }) + expect(wrapper.find(selector).exists()).toBe(true) }) }) diff --git a/packages/overlay/src/index.vue b/packages/overlay/src/index.vue index e3efde80ab..ea7cc5723d 100644 --- a/packages/overlay/src/index.vue +++ b/packages/overlay/src/index.vue @@ -1,5 +1,5 @@