提交 | 用户 | age
|
2a61f6
|
1 |
import { mount, createLocalVue } from '@vue/test-utils' |
L |
2 |
import VueRouter from 'vue-router' |
|
3 |
import ElementUI from 'element-ui' |
|
4 |
import Breadcrumb from '@/components/Breadcrumb/index.vue' |
|
5 |
|
|
6 |
const localVue = createLocalVue() |
|
7 |
localVue.use(VueRouter) |
|
8 |
localVue.use(ElementUI) |
|
9 |
|
|
10 |
const routes = [ |
|
11 |
{ |
|
12 |
path: '/', |
|
13 |
name: 'home', |
|
14 |
children: [{ |
|
15 |
path: 'dashboard', |
|
16 |
name: 'dashboard' |
|
17 |
}] |
|
18 |
}, |
|
19 |
{ |
|
20 |
path: '/menu', |
|
21 |
name: 'menu', |
|
22 |
children: [{ |
|
23 |
path: 'menu1', |
|
24 |
name: 'menu1', |
|
25 |
meta: { title: 'menu1' }, |
|
26 |
children: [{ |
|
27 |
path: 'menu1-1', |
|
28 |
name: 'menu1-1', |
|
29 |
meta: { title: 'menu1-1' } |
|
30 |
}, |
|
31 |
{ |
|
32 |
path: 'menu1-2', |
|
33 |
name: 'menu1-2', |
|
34 |
redirect: 'noredirect', |
|
35 |
meta: { title: 'menu1-2' }, |
|
36 |
children: [{ |
|
37 |
path: 'menu1-2-1', |
|
38 |
name: 'menu1-2-1', |
|
39 |
meta: { title: 'menu1-2-1' } |
|
40 |
}, |
|
41 |
{ |
|
42 |
path: 'menu1-2-2', |
|
43 |
name: 'menu1-2-2' |
|
44 |
}] |
|
45 |
}] |
|
46 |
}] |
|
47 |
}] |
|
48 |
|
|
49 |
const router = new VueRouter({ |
|
50 |
routes |
|
51 |
}) |
|
52 |
|
|
53 |
describe('Breadcrumb.vue', () => { |
|
54 |
const wrapper = mount(Breadcrumb, { |
|
55 |
localVue, |
|
56 |
router |
|
57 |
}) |
|
58 |
it('dashboard', () => { |
|
59 |
router.push('/dashboard') |
|
60 |
const len = wrapper.findAll('.el-breadcrumb__inner').length |
|
61 |
expect(len).toBe(1) |
|
62 |
}) |
|
63 |
it('normal route', () => { |
|
64 |
router.push('/menu/menu1') |
|
65 |
const len = wrapper.findAll('.el-breadcrumb__inner').length |
|
66 |
expect(len).toBe(2) |
|
67 |
}) |
|
68 |
it('no meta.title', () => { |
|
69 |
router.push('/menu/menu1/menu1-2/menu1-2-2') |
|
70 |
const len = wrapper.findAll('.el-breadcrumb__inner').length |
|
71 |
expect(len).toBe(3) |
|
72 |
}) |
|
73 |
// it('click link', () => { |
|
74 |
// router.push('/menu/menu1/menu1-2/menu1-2-2') |
|
75 |
// const breadcrumbArray = wrapper.findAll('.el-breadcrumb__inner') |
|
76 |
// const second = breadcrumbArray.at(1) |
|
77 |
// console.log(breadcrumbArray) |
|
78 |
// const href = second.find('a').attributes().href |
|
79 |
// expect(href).toBe('#/menu/menu1') |
|
80 |
// }) |
|
81 |
// it('noRedirect', () => { |
|
82 |
// router.push('/menu/menu1/menu1-2/menu1-2-1') |
|
83 |
// const breadcrumbArray = wrapper.findAll('.el-breadcrumb__inner') |
|
84 |
// const redirectBreadcrumb = breadcrumbArray.at(2) |
|
85 |
// expect(redirectBreadcrumb.contains('a')).toBe(false) |
|
86 |
// }) |
|
87 |
it('last breadcrumb', () => { |
|
88 |
router.push('/menu/menu1/menu1-2/menu1-2-1') |
|
89 |
const breadcrumbArray = wrapper.findAll('.el-breadcrumb__inner') |
|
90 |
const redirectBreadcrumb = breadcrumbArray.at(3) |
|
91 |
expect(redirectBreadcrumb.contains('a')).toBe(false) |
|
92 |
}) |
|
93 |
}) |