button.spec.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { shallowMount, mount } from '@vue/test-utils'
  2. import Button from '../button.vue';
  3. import Vue from 'vue';
  4. describe('Button.vue', () => {
  5. let wrapper = shallowMount(Button, {
  6. slots: {
  7. default: '去结算'
  8. }
  9. });
  10. it('设置type', () => {
  11. wrapper.setProps({
  12. type: 'light'
  13. })
  14. return Vue.nextTick().then(function () {
  15. expect(wrapper.attributes('class')).toContain('light');
  16. })
  17. });
  18. it('设置slot', () => {
  19. return Vue.nextTick().then(function () {
  20. expect(wrapper.text()).toBe('去结算');
  21. })
  22. });
  23. it('设置disabled', () => {
  24. wrapper.setProps({
  25. disabled: true
  26. })
  27. return Vue.nextTick().then(function () {
  28. expect(wrapper.text()).toBe('去结算');
  29. expect(wrapper.attributes('disabled')).toContain('disabled');
  30. })
  31. });
  32. it('设置shape', () => {
  33. wrapper.setProps({
  34. shape: 'circle'
  35. })
  36. return Vue.nextTick().then(function () {
  37. expect(wrapper.text()).toBe('去结算');
  38. expect(wrapper.attributes('class')).toContain('circle');
  39. })
  40. });
  41. it('设置small', () => {
  42. wrapper.setProps({
  43. small: true
  44. })
  45. return Vue.nextTick().then(function () {
  46. expect(wrapper.text()).toBe('去结算');
  47. expect(wrapper.attributes('class')).toContain('small');
  48. })
  49. });
  50. it('设置icon', () => {
  51. wrapper.setProps({
  52. type: 'actived',
  53. icon: 'tick'
  54. })
  55. return Vue.nextTick().then(function () {
  56. expect(wrapper.text()).toBe('去结算');
  57. expect(wrapper.contains('.txt-icon')).toBe(true);
  58. expect(wrapper.find('.txt-icon').attributes('type')).toBe('tick');
  59. expect(wrapper.find('span').text()).toBe('去结算');
  60. })
  61. });
  62. it('设置color', () => {
  63. wrapper.setProps({
  64. icon: 'tick',
  65. color: '#fff'
  66. })
  67. return Vue.nextTick().then(function () {
  68. expect(wrapper.text()).toBe('去结算');
  69. expect(wrapper.find('span').attributes('style')).toBe('color: rgb(255, 255, 255);');
  70. expect(wrapper.find('.txt-icon').attributes('color')).toBe('#fff');
  71. })
  72. });
  73. });