From ca4201d0b1967318b73bf59736d50cc00e859fc4 Mon Sep 17 00:00:00 2001 From: lVAL Date: Thu, 31 Dec 2020 13:38:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/unit/components/Breadcrumb.spec.js | 178 +++++++++++------------ tests/unit/components/Hamburger.spec.js | 35 ++--- tests/unit/components/SvgIcon.spec.js | 42 +++--- 3 files changed, 128 insertions(+), 127 deletions(-) diff --git a/tests/unit/components/Breadcrumb.spec.js b/tests/unit/components/Breadcrumb.spec.js index 1d94c8fc7..8f58e593d 100644 --- a/tests/unit/components/Breadcrumb.spec.js +++ b/tests/unit/components/Breadcrumb.spec.js @@ -1,98 +1,98 @@ -import { mount, createLocalVue } from '@vue/test-utils' -import VueRouter from 'vue-router' -import ElementUI from 'element-ui' -import Breadcrumb from '@/components/Breadcrumb/index.vue' +import { mount, createLocalVue } from '@vue/test-utils'; +import VueRouter from 'vue-router'; +import ElementUI from 'element-ui'; +import Breadcrumb from '@/components/Breadcrumb/index.vue'; -const localVue = createLocalVue() -localVue.use(VueRouter) -localVue.use(ElementUI) +const localVue = createLocalVue(); +localVue.use(VueRouter); +localVue.use(ElementUI); const routes = [ - { - path: '/', - name: 'home', - children: [{ - path: 'dashboard', - name: 'dashboard' - }] - }, - { - path: '/menu', - name: 'menu', - children: [{ - path: 'menu1', - name: 'menu1', - meta: { title: 'menu1' }, - children: [{ - path: 'menu1-1', - name: 'menu1-1', - meta: { title: 'menu1-1' } - }, - { - path: 'menu1-2', - name: 'menu1-2', - redirect: 'noredirect', - meta: { title: 'menu1-2' }, + { + path: '/', + name: 'home', children: [{ - path: 'menu1-2-1', - name: 'menu1-2-1', - meta: { title: 'menu1-2-1' } - }, - { - path: 'menu1-2-2', - name: 'menu1-2-2' + path: 'dashboard', + name: 'dashboard' }] - }] - }] - }] + }, + { + path: '/menu', + name: 'menu', + children: [{ + path: 'menu1', + name: 'menu1', + meta: { title: 'menu1' }, + children: [{ + path: 'menu1-1', + name: 'menu1-1', + meta: { title: 'menu1-1' } + }, + { + path: 'menu1-2', + name: 'menu1-2', + redirect: 'noredirect', + meta: { title: 'menu1-2' }, + children: [{ + path: 'menu1-2-1', + name: 'menu1-2-1', + meta: { title: 'menu1-2-1' } + }, + { + path: 'menu1-2-2', + name: 'menu1-2-2' + }] + }] + }] + }]; const router = new VueRouter({ - routes -}) + routes +}); describe('Breadcrumb.vue', () => { - const wrapper = mount(Breadcrumb, { - localVue, - router - }) - it('dashboard', () => { - router.push('/dashboard') - const len = wrapper.findAll('.el-breadcrumb__inner').length - expect(len).toBe(1) - }) - it('normal route', () => { - router.push('/menu/menu1') - const len = wrapper.findAll('.el-breadcrumb__inner').length - expect(len).toBe(2) - }) - it('nested route', () => { - router.push('/menu/menu1/menu1-2/menu1-2-1') - const len = wrapper.findAll('.el-breadcrumb__inner').length - expect(len).toBe(4) - }) - it('no meta.title', () => { - router.push('/menu/menu1/menu1-2/menu1-2-2') - const len = wrapper.findAll('.el-breadcrumb__inner').length - expect(len).toBe(3) - }) - // it('click link', () => { - // router.push('/menu/menu1/menu1-2/menu1-2-2') - // const breadcrumbArray = wrapper.findAll('.el-breadcrumb__inner') - // const second = breadcrumbArray.at(1) - // console.log(breadcrumbArray) - // const href = second.find('a').attributes().href - // expect(href).toBe('#/menu/menu1') - // }) - // it('noRedirect', () => { - // router.push('/menu/menu1/menu1-2/menu1-2-1') - // const breadcrumbArray = wrapper.findAll('.el-breadcrumb__inner') - // const redirectBreadcrumb = breadcrumbArray.at(2) - // expect(redirectBreadcrumb.contains('a')).toBe(false) - // }) - it('last breadcrumb', () => { - router.push('/menu/menu1/menu1-2/menu1-2-1') - const breadcrumbArray = wrapper.findAll('.el-breadcrumb__inner') - const redirectBreadcrumb = breadcrumbArray.at(3) - expect(redirectBreadcrumb.contains('a')).toBe(false) - }) -}) + const wrapper = mount(Breadcrumb, { + localVue, + router + }); + it('dashboard', () => { + router.push('/dashboard'); + const len = wrapper.findAll('.el-breadcrumb__inner').length; + expect(len).toBe(1); + }); + it('normal route', () => { + router.push('/menu/menu1'); + const len = wrapper.findAll('.el-breadcrumb__inner').length; + expect(len).toBe(2); + }); + it('nested route', () => { + router.push('/menu/menu1/menu1-2/menu1-2-1'); + const len = wrapper.findAll('.el-breadcrumb__inner').length; + expect(len).toBe(4); + }); + it('no meta.title', () => { + router.push('/menu/menu1/menu1-2/menu1-2-2'); + const len = wrapper.findAll('.el-breadcrumb__inner').length; + expect(len).toBe(3); + }); + // it('click link', () => { + // router.push('/menu/menu1/menu1-2/menu1-2-2') + // const breadcrumbArray = wrapper.findAll('.el-breadcrumb__inner') + // const second = breadcrumbArray.at(1) + // console.log(breadcrumbArray) + // const href = second.find('a').attributes().href + // expect(href).toBe('#/menu/menu1') + // }) + // it('noRedirect', () => { + // router.push('/menu/menu1/menu1-2/menu1-2-1') + // const breadcrumbArray = wrapper.findAll('.el-breadcrumb__inner') + // const redirectBreadcrumb = breadcrumbArray.at(2) + // expect(redirectBreadcrumb.contains('a')).toBe(false) + // }) + it('last breadcrumb', () => { + router.push('/menu/menu1/menu1-2/menu1-2-1'); + const breadcrumbArray = wrapper.findAll('.el-breadcrumb__inner'); + const redirectBreadcrumb = breadcrumbArray.at(3); + expect(redirectBreadcrumb.contains('a')).toBe(false); + }); +}); diff --git a/tests/unit/components/Hamburger.spec.js b/tests/unit/components/Hamburger.spec.js index 01ea303a5..426a8934a 100644 --- a/tests/unit/components/Hamburger.spec.js +++ b/tests/unit/components/Hamburger.spec.js @@ -1,18 +1,19 @@ -import { shallowMount } from '@vue/test-utils' -import Hamburger from '@/components/Hamburger/index.vue' +import { shallowMount } from '@vue/test-utils'; +import Hamburger from '@/components/Hamburger/index.vue'; + describe('Hamburger.vue', () => { - it('toggle click', () => { - const wrapper = shallowMount(Hamburger) - const mockFn = jest.fn() - wrapper.vm.$on('toggleClick', mockFn) - wrapper.find('.hamburger').trigger('click') - expect(mockFn).toBeCalled() - }) - it('prop isActive', () => { - const wrapper = shallowMount(Hamburger) - wrapper.setProps({ isActive: true }) - expect(wrapper.contains('.is-active')).toBe(true) - wrapper.setProps({ isActive: false }) - expect(wrapper.contains('.is-active')).toBe(false) - }) -}) + it('toggle click', () => { + const wrapper = shallowMount(Hamburger); + const mockFn = jest.fn(); + wrapper.vm.$on('toggleClick', mockFn); + wrapper.find('.hamburger').trigger('click'); + expect(mockFn).toBeCalled(); + }); + it('prop isActive', () => { + const wrapper = shallowMount(Hamburger); + wrapper.setProps({ isActive: true }); + expect(wrapper.contains('.is-active')).toBe(true); + wrapper.setProps({ isActive: false }); + expect(wrapper.contains('.is-active')).toBe(false); + }); +}); diff --git a/tests/unit/components/SvgIcon.spec.js b/tests/unit/components/SvgIcon.spec.js index 31467a9f6..3b4b1be83 100644 --- a/tests/unit/components/SvgIcon.spec.js +++ b/tests/unit/components/SvgIcon.spec.js @@ -1,22 +1,22 @@ -import { shallowMount } from '@vue/test-utils' -import SvgIcon from '@/components/SvgIcon/index.vue' +import { shallowMount } from '@vue/test-utils'; +import SvgIcon from '@/components/SvgIcon/index.vue'; describe('SvgIcon.vue', () => { - it('iconClass', () => { - const wrapper = shallowMount(SvgIcon, { - propsData: { - iconClass: 'test' - } - }) - expect(wrapper.find('use').attributes().href).toBe('#icon-test') - }) - it('className', () => { - const wrapper = shallowMount(SvgIcon, { - propsData: { - iconClass: 'test' - } - }) - expect(wrapper.classes().length).toBe(1) - wrapper.setProps({ className: 'test' }) - expect(wrapper.classes().includes('test')).toBe(true) - }) -}) + it('iconClass', () => { + const wrapper = shallowMount(SvgIcon, { + propsData: { + iconClass: 'test' + } + }); + expect(wrapper.find('use').attributes().href).toBe('#icon-test'); + }); + it('className', () => { + const wrapper = shallowMount(SvgIcon, { + propsData: { + iconClass: 'test' + } + }); + expect(wrapper.classes().length).toBe(1); + wrapper.setProps({ className: 'test' }); + expect(wrapper.classes().includes('test')).toBe(true); + }); +});