Blame view
tests/unit/components/Breadcrumb.spec.js
2.61 KB
80a28914e init |
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 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' 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' }, 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 }) 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) }) }) |