Breadcrumb.spec.js 2.4 KB

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