tab.spec.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { shallowMount, mount } from '@vue/test-utils'
  2. import Tab from '../tab.vue';
  3. import Vue from 'vue';
  4. describe('Tab.vue', () => {
  5. const wrapper = mount(Tab);
  6. // it('页签类型为based', () => {
  7. // wrapper.setProps({ type: 'based' });
  8. // return Vue.nextTick().then(function () {
  9. // expect(wrapper.contains('.based')).toBe(true);
  10. // })
  11. // });
  12. it('当前tab的位置', () => {
  13. wrapper.setProps({ positionNav: 'left' });
  14. return Vue.nextTick().then(function () {
  15. expect(wrapper.contains('.nut-tab-title-leftnav')).toBe(true);
  16. })
  17. });
  18. // it('是否显示内容区域', () => {
  19. // wrapper.setProps({ contentShow: true });
  20. // return Vue.nextTick().then(function () {
  21. // expect(wrapper.contains('.nut-tab-item')).toBe(true);
  22. // })
  23. // });
  24. it('禁止选择第一个标签', () => {
  25. wrapper.setData({ tabTitleList: [
  26. {
  27. tabTitle: "衣物",
  28. disable: true,
  29. iconUrl:
  30. "http://img13.360buyimg.com/uba/jfs/t27280/289/2061314663/2392/872e32ff/5bf76318Ndc80c1d8.jpg",
  31. content: "<p>衣物内容</p>"
  32. },
  33. {
  34. tabTitle: "日用品",
  35. iconUrl:
  36. "http://img13.360buyimg.com/uba/jfs/t30331/209/562746340/2190/6619973d/5bf763aaN6ff02099.jpg",
  37. content: "<p>日用品内容</p>"
  38. },
  39. {
  40. tabTitle: "运动器材",
  41. iconUrl:
  42. "http://img20.360buyimg.com/uba/jfs/t30346/262/553689202/2257/5dfa3983/5bf76407N72deabf4.jpg",
  43. content: "<p>运动器材内容</p>"
  44. },
  45. {
  46. tabTitle: "电影票",
  47. iconUrl:
  48. "http://img10.360buyimg.com/uba/jfs/t26779/215/2118525153/2413/470d1613/5bf767b2N075957b7.jpg",
  49. content: "<p>电影票内容</p>"
  50. }
  51. ] });
  52. return Vue.nextTick().then(function () {
  53. expect(wrapper.findAll('.nut-title-nav-leftnav').at(0).is('.nut-tab-disable')).toBe(true)
  54. })
  55. });
  56. it('当前默认选中的tab', () => {
  57. wrapper.setProps({ positionNav: 'top' });
  58. return Vue.nextTick().then(function () {
  59. expect(wrapper.findAll('.nut-title-nav-list').at(0).is('.nut-tab-active')).toBe(true)
  60. })
  61. });
  62. it('tab标签标题', () => {
  63. return Vue.nextTick().then(function () {
  64. expect(wrapper.findAll('.nut-title-nav').at(0).text()).toBe('衣物');
  65. })
  66. });
  67. it('点击tab标签', () => {
  68. return Vue.nextTick().then(function () {
  69. wrapper.findAll('.nut-title-nav-list').at(1).trigger('click');
  70. expect(wrapper.findAll('.nut-title-nav-list').at(1).is('.nut-tab-active')).toBe(true)
  71. })
  72. });
  73. });