1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| import { describe, it, expect } from 'vitest' import { mount } from '@vue/test-utils' import Nav from '../Nav.vue'
describe('Nav.vue gets the following array from the parent element frontLayout.vue', () => { const navLists = [ { id_set: '001', title: '出勤打卡', href: '/' }, { id_set: '002', title: '出勤設定', href: '/set_check' }, { id_set: '003', title: '出勤列表', href: '/work_check_lists' }, { id_set:'004', title:'出勤行事曆', href:'/work_calendar'} ] const pageNameActive = '001'; const wrapper = mount(Nav, { props: { navLists: navLists, pageNameActive:pageNameActive } }) it('Is navLists data correctly rendering information? ', () => { const items = wrapper.findAll('li'); expect(items.length).toBe(4); expect(items[0].text()).toBe('出勤打卡'); expect(items[1].text()).toBe('出勤設定'); expect(items[2].text()).toBe('出勤列表'); expect(items[3].text()).toBe('出勤行事曆'); }); it('pageNameActive is rendered when the initial value is passed', () => { expect(pageNameActive).toMatch(pageNameActive); })
it('Emits the event of the current data when clicked', () => { const items = wrapper.findAll('li'); const button = wrapper.find('li'); button.trigger('click'); expect(pageNameActive).toMatch(items[0].id_set); expect(pageNameActive).toMatch(items[1].id_set) expect(pageNameActive).toMatch(items[2].id_set) expect(pageNameActive).toMatch(items[3].id_set) expect(button.find('li.isActive')); }) //emitted ,toHaveProperty 點擊時取出當筆數據的事件 it('Event to retrieve the current data when clicked', async () => { await wrapper.get('[data-test="button"]').trigger('click') expect(wrapper.emitted()).toHaveProperty('sendMenuClickActive') }) })
|