From d05deff64c194efd426e4da85e592e88ea18c957 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AD=B8=E6=BE=A4Morty=20Li?= Date: Mon, 15 Jan 2024 15:39:48 +0800 Subject: [PATCH] test: add IconEye test --- popup/src/components/icons/IconEye.spec.ts | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 popup/src/components/icons/IconEye.spec.ts diff --git a/popup/src/components/icons/IconEye.spec.ts b/popup/src/components/icons/IconEye.spec.ts new file mode 100644 index 0000000..aaf86ad --- /dev/null +++ b/popup/src/components/icons/IconEye.spec.ts @@ -0,0 +1,43 @@ +import { mount } from '@vue/test-utils' +import { describe, expect, it } from 'vitest' + +import { Icon } from '@iconify/vue' +import IconEye from './IconEye.vue' + +const mountElement = (props?: { isOpen?: boolean }) => { + const defaultProps = { + isOpen: true + } + + return mount(IconEye, { + props: { + ...defaultProps, + ...props + } + }) +} +describe('IconEye.vue', () => { + it('render eye-off icon when isOpen', () => { + const wrapper = mountElement({ + isOpen: true + }) + + const icon = wrapper.findComponent(Icon) + expect(icon.vm.$attrs.icon).toBe('iconamoon:eye-off') + }) + + it('render eye-open icon when is not open', () => { + const wrapper = mountElement({ + isOpen: false + }) + + const icon = wrapper.findComponent(Icon) + expect(icon.vm.$attrs.icon).toBe('iconamoon:eye') + }) + + it('emits the clickEye event when clicked', async () => { + const wrapper = mountElement() + await wrapper.trigger('click') + expect(wrapper.emitted()).toHaveProperty('clickEye') + }) +})