diff --git a/packages/notification/__tests__/notification.spec.ts b/packages/notification/__tests__/notification.spec.ts index e6bb3e9c1c..388ed87dd9 100644 --- a/packages/notification/__tests__/notification.spec.ts +++ b/packages/notification/__tests__/notification.spec.ts @@ -33,7 +33,7 @@ describe('Notification.vue', () => { expect(wrapper.vm.typeClass).toBe('') expect(wrapper.vm.horizontalClass).toBe('right') expect(wrapper.vm.verticalProperty).toBe('top') - expect(wrapper.vm.positionStyle).toEqual({ top: 0 }) + expect(wrapper.vm.positionStyle).toEqual({ top: '0px' }) }) test('should be able to render VNode', () => { @@ -86,21 +86,6 @@ describe('Notification.vue', () => { offMock.mockRestore() }) - test('should call init function when it\'s provided', () => { - const _init = jest.fn() - const wrapper = _mount({ - slots: { - default: AXIOM, - }, - props: { - _init, - _idx: 0, - }, - }) - expect(_init).toHaveBeenCalled() - wrapper.unmount() - }) - test('should add event listener to target element when init', () => { jest.spyOn(domExports, 'on') @@ -243,10 +228,12 @@ describe('Notification.vue', () => { const wrapper = _mount({ props: { duration: 0, + onClick: jest.fn(), }, }) + await wrapper.trigger('click') - expect(wrapper.emitted('click')).toHaveLength(1) + expect(wrapper.vm.onClick).toHaveBeenCalledTimes(1) }) test('should be able to delete timer when press delete', async () => { @@ -282,10 +269,12 @@ describe('Notification.vue', () => { keyCode: eventKeys.esc, // eslint-disable-next-line } as any) + const oldClose = wrapper.vm.close + wrapper.vm.close = jest.fn(() => oldClose()) document.dispatchEvent(event) jest.runAllTimers() expect(wrapper.vm.closed).toBe(true) - expect(wrapper.emitted('close')).toHaveLength(1) + expect(wrapper.vm.close).toHaveBeenCalledTimes(1) }) }) }) diff --git a/packages/notification/__tests__/notify.spec.ts b/packages/notification/__tests__/notify.spec.ts index cffbb49853..1c400211aa 100644 --- a/packages/notification/__tests__/notify.spec.ts +++ b/packages/notification/__tests__/notify.spec.ts @@ -1,4 +1,6 @@ +import { isVNode } from 'vue' import Notification, { close, closeAll } from '../src/notify' +import type { NotificationVM } from '../src/notification.constants' jest.useFakeTimers() @@ -10,15 +12,15 @@ describe('Notification on command', () => { }) test('it should get component instance when calling notification constructor', async () => { - const vm = Notification({}) - expect(vm).toBeNull() + const vm = Notification() + expect(isVNode(vm)).toBe(true) expect(document.querySelector(selector)).toBeDefined() jest.runAllTicks() }) test('it should be able to close notification by manually close', () => { - Notification({}) + Notification() const element = document.querySelector(selector) expect(element).toBeDefined() close(element.id) @@ -26,11 +28,18 @@ describe('Notification on command', () => { }) test('it should close all notifications', () => { + const notifications: NotificationVM[] = [] + const onClose = jest.fn() for (let i = 0; i < 4; i++) { - Notification({}) + notifications.push(Notification({ + onClose, + })) } expect(document.querySelectorAll(selector).length).toBe(4) closeAll() + for (let i = 0; i < notifications.length; i++) { + expect(onClose).toHaveBeenCalledTimes(4) + } expect(document.querySelectorAll(selector).length).toBe(0) }) diff --git a/packages/notification/src/index.vue b/packages/notification/src/index.vue index 79a5d142f6..d923ce8602 100644 --- a/packages/notification/src/index.vue +++ b/packages/notification/src/index.vue @@ -1,7 +1,7 @@