DevCloudFE / vue-devui

UI components based on Vue3 and DevUI Design
https://vue-devui.github.io
MIT License
1.04k stars 290 forks source link

解决单元测试报错问题 #1325

Closed kagol closed 2 years ago

kagol commented 2 years ago

目前还有19个单元测试未通过:

https://github.com/DevCloudFE/vue-devui/runs/8225861666?check_suite_focus=true

本地执行以下命令可执行单元测试,并看到单元测试的结果:

pnpm test

报错详情如下:

Summary of all failing tests
FAIL devui/table/__tests__/table.spec.tsx (10.887 s)
  ● d-table › sort

    expect(received).toBe(expected) // Object.is equality

    Expected: "1990/01/12"
    Received: "1990/01/11"

      279 |     const tableBody = table.find(ns.e('tbody'));
      280 |     const lastTd = tableBody.find('tr').findAll('td')[3];
    > 281 |     expect(lastTd.text()).toBe('1990/01/12');
          |                           ^
      282 |
      283 |     const sortIcon = lastTh.find(ns.e('sort-clickable'));
      284 |     await sortIcon.trigger('click');

      at Object.<anonymous> (devui/table/__tests__/table.spec.tsx:281:27)

FAIL devui/date-picker-pro/__tests__/date-picker-pro.spec.tsx
  ● date-picker-pro test › date-picker-pro showTime props

    expect(received).toBe(expected) // Object.is equality

    Expected: "2022/09/08 03:00:00"
    Received: "2022/09/08 12:00:00"

      195 |     const liItems = timeUl?.[0].querySelectorAll('.time-li');
      196 |     await liItems?.[3].dispatchEvent(new Event('click'));
    > 197 |     expect(dayjs(datePickerProValue.value).format(TIME_FORMAT)).toBe(`${getSelectedDate(todayIndex, date)} 03:00:00`);
          |                                                                 ^
      198 |
      199 |     const pickerPanelFooter = document.querySelector(ns.e('panel-footer'));
      200 |     const button = pickerPanelFooter?.getElementsByTagName('button')[0];

      at Object.<anonymous> (devui/date-picker-pro/__tests__/date-picker-pro.spec.tsx:197:65)

  ● date-picker-pro test › date-picker-pro event toggleChange confirmEvent focus blur

    expect(jest.fn()).toBeCalledTimes(expected)

    Expected number of calls: 1
    Received number of calls: 0

      244 |     const Items = monthContentContainer?.querySelectorAll('td');
      245 |     await Items?.[selectIndex].dispatchEvent(new Event('click'));
    > 246 |     expect(onConfirmEvent).toBeCalledTimes(1);
          |                            ^
      247 |     expect(onToggleChange).toBeCalledTimes(2);
      248 |     expect(onBlur).toBeCalledTimes(1);
      249 |

      at Object.<anonymous> (devui/date-picker-pro/__tests__/date-picker-pro.spec.tsx:246:28)

  ● date-picker-pro test › date-picker-pro rightArea slot

    expect(received).toBeTruthy()

    Received: null

      335 |     const pickerPanel = document.querySelector(pickerPanelClass);
      336 |     const rightArea = pickerPanel?.querySelector(ns.e('panel-right-area'));
    > 337 |     expect(rightArea).toBeTruthy();
          |                       ^
      338 |
      339 |     const button = rightArea?.getElementsByTagName('button')[0];
      340 |     expect(button).toBeTruthy();

      at Object.<anonymous> (devui/date-picker-pro/__tests__/date-picker-pro.spec.tsx:337:23)

  ● date-picker-pro test › date-picker-pro footer slot

    expect(received).toBe(expected) // Object.is equality
      130 |     expect(nodes[0].find(`${ns.e('node-folder')} > svg`).exists()).toBe(true);
      131 |     expect(nodes[0].find(ns.e('node-vline')).exists()).not.toBe(true);

      at Object.<anonymous> (devui/tree/__tests__/basic-tree/basic-tree.spec.tsx:128:19)

FAIL devui/tree/__tests__/dragdrop-tree/dragdrop-tree.spec.tsx
  ● Draggable tree › Basic default node drag.

    expect(received).toBe(expected) // Object.is equality

    Expected: "parent node 5"
    Received: "parent node 2"

      70 |     await startDragging(dragNode, dropNode, 10);
      71 |     expect(childNodeList[0].text()).toBe('parent node 1');
    > 72 |     expect(childNodeList[1].text()).toBe('parent node 5');
         |                                     ^
      73 |     expect(childNodeList[2].text()).toBe('leaf node 5-1');
      74 |     expect(childNodeList[3].text()).toBe('leaf node 5-2');
      75 |     expect(childNodeList[4].text()).toBe('parent node 2');

      at Object.<anonymous> (devui/tree/__tests__/dragdrop-tree/dragdrop-tree.spec.tsx:72:37)

  ● Draggable tree › Basic sortable node drag.

    expect(received).toBe(expected) // Object.is equality

    Expected: "leaf node 5-2"
    Received: "parent node 1"

      84 |     const dropNode = childNodeList[0];
      85 |     await startDragging(dragNode, dropNode, -1);
    > 86 |     expect(childNodeList[0].text()).toBe('leaf node 5-2');
         |                                     ^
      87 |     wrapper.unmount();
      88 |
      89 |     // test dropInner

      at Object.<anonymous> (devui/tree/__tests__/dragdrop-tree/dragdrop-tree.spec.tsx:86:37)

FAIL devui/tree/__tests__/lazy-node-tree/node-lazy-tree.spec.tsx
  ● Tree node lazyLoad › node dynamic loading

    expect(received).toBeTruthy()

    Received: false

      54 |
      55 |     const loadingContent = loadingItem.find(loadingNs.b());
    > 56 |     expect(loadingContent.exists()).toBeTruthy();
         |                                     ^
      57 |
      58 |     await new Promise((resolve) => {
      59 |       setTimeout(resolve, 600);

      at Object.<anonymous> (devui/tree/__tests__/lazy-node-tree/node-lazy-tree.spec.tsx:56:37)

Test Suites: 9 failed, 80 passed, 89 total
Tests:       19 failed, 85 todo, 514 passed, 618 total
jxhhdx commented 2 years ago

这个问题我处理一下