ellipsis-text.test.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { mount } from '@vue/test-utils';
  2. import { describe, expect, it } from 'vitest';
  3. import { EllipsisText } from '..';
  4. describe('ellipsis-text.vue', () => {
  5. it('renders the correct content and truncates text', async () => {
  6. const wrapper = mount(EllipsisText, {
  7. props: {
  8. line: 1,
  9. title: 'Test Title',
  10. },
  11. slots: {
  12. default: 'This is a very long text that should be truncated.',
  13. },
  14. });
  15. expect(wrapper.text()).toContain('This is a very long text');
  16. // 检查 ellipsis 是否应用了正确的 class
  17. const ellipsis = wrapper.find('.truncate');
  18. expect(ellipsis.exists()).toBe(true);
  19. });
  20. it('expands text on click if expand is true', async () => {
  21. const wrapper = mount(EllipsisText, {
  22. props: {
  23. expand: true,
  24. line: 1,
  25. },
  26. slots: {
  27. default: 'This is a very long text that should be truncated.',
  28. },
  29. });
  30. const ellipsis = wrapper.find('.truncate');
  31. await ellipsis.trigger('click');
  32. expect(wrapper.emitted('expandChange')).toBeTruthy();
  33. });
  34. });