diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a13a97238..bd2a5f2e9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -108,6 +108,6 @@ jobs: key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }} - name: coverage - run: npm test -- --coverage && bash <(curl -s https://codecov.io/bash) + run: npm run coverage && bash <(curl -s https://codecov.io/bash) needs: setup diff --git a/.gitignore b/.gitignore index 2c1b5ee4b..3111e398c 100644 --- a/.gitignore +++ b/.gitignore @@ -32,7 +32,7 @@ package-lock.json es/ .storybook .doc -!tests/__mocks__/rc-util/lib +!__mocks__/rc-util/lib examples/debug.tsx .history ~* @@ -42,4 +42,4 @@ examples/debug.tsx .umi-production .umi-test .env.local -.dumi \ No newline at end of file +.dumi diff --git a/tests/__mocks__/rc-util/lib/getScrollBarSize.ts b/__mocks__/rc-util/lib/getScrollBarSize.ts similarity index 100% rename from tests/__mocks__/rc-util/lib/getScrollBarSize.ts rename to __mocks__/rc-util/lib/getScrollBarSize.ts diff --git a/jest.config.js b/jest.config.js deleted file mode 100644 index 86627c33b..000000000 --- a/jest.config.js +++ /dev/null @@ -1,4 +0,0 @@ -module.exports = { - setupFiles: ['./tests/setup.js'], - snapshotSerializers: [require.resolve('enzyme-to-json/serializer')], -}; diff --git a/package.json b/package.json index a26e93c16..1e54808c4 100644 --- a/package.json +++ b/package.json @@ -40,8 +40,8 @@ "compile": "father build && lessc assets/index.less assets/index.css", "deploy": "npm run docs:build && npm run docs:deploy", "prettier": "prettier --write \"**/*.{js,jsx,tsx,ts,less,md,json}\"", - "test": "rc-test", - "coverage": "rc-test --coverage", + "test": "vitest", + "coverage": "vitest run --coverage", "prepublishOnly": "npm run compile && np --no-cleanup --yolo --no-publish", "lint": "eslint src/ --ext .tsx,.ts", "lint:tsc": "tsc -p tsconfig.json --noEmit", @@ -63,7 +63,6 @@ "@testing-library/jest-dom": "^5.16.5", "@testing-library/react": "^12.1.5", "@types/enzyme": "^3.10.5", - "@types/jest": "^28.1.2", "@types/react": "^17.0.35", "@types/react-dom": "^18.0.5", "@types/responselike": "^1.0.0", @@ -86,7 +85,6 @@ "rc-animate": "^3.0.0", "rc-dropdown": "~4.0.1", "rc-menu": "~9.6.0", - "rc-test": "^7.0.14", "rc-tooltip": "^5.2.1", "react": "^16.0.0", "react-dnd": "^2.5.4", @@ -97,7 +95,11 @@ "react-window": "^1.8.5", "regenerator-runtime": "^0.13.7", "styled-components": "^5.0.1", - "typescript": "^4.8.4" + "typescript": "^4.8.4", + "@vitest/coverage-c8": "^0.31.0", + "@types/testing-library__jest-dom": "^5.14.5", + "jsdom": "^22.0.0", + "vitest": "^0.31.0" }, "lint-staged": { "**/*.{js,jsx,tsx,ts,md,json}": [ diff --git a/src/stickyScrollBar.tsx b/src/stickyScrollBar.tsx index 712878283..6aa84777b 100644 --- a/src/stickyScrollBar.tsx +++ b/src/stickyScrollBar.tsx @@ -1,10 +1,10 @@ +import { useContext } from '@rc-component/context'; import classNames from 'classnames'; import addEventListener from 'rc-util/lib/Dom/addEventListener'; import { getOffset } from 'rc-util/lib/Dom/css'; import getScrollBarSize from 'rc-util/lib/getScrollBarSize'; import * as React from 'react'; import TableContext from './context/TableContext'; -import { useContext } from '@rc-component/context'; import { useLayoutState } from './hooks/useFrame'; interface StickyScrollBarProps { diff --git a/tests/ColSpan.spec.js b/tests/ColSpan.spec.jsx similarity index 100% rename from tests/ColSpan.spec.js rename to tests/ColSpan.spec.jsx diff --git a/tests/Colgroup.spec.js b/tests/Colgroup.spec.jsx similarity index 100% rename from tests/Colgroup.spec.js rename to tests/Colgroup.spec.jsx index 1b88224f6..e112721a6 100644 --- a/tests/Colgroup.spec.js +++ b/tests/Colgroup.spec.jsx @@ -1,5 +1,5 @@ -import React from 'react'; import { mount } from 'enzyme'; +import React from 'react'; import Table, { INTERNAL_COL_DEFINE } from '../src'; describe('Table.ColGroup', () => { diff --git a/tests/Deprecated.spec.js b/tests/Deprecated.spec.jsx similarity index 90% rename from tests/Deprecated.spec.js rename to tests/Deprecated.spec.jsx index 12cb00988..274c6b546 100644 --- a/tests/Deprecated.spec.js +++ b/tests/Deprecated.spec.jsx @@ -1,13 +1,13 @@ -import React from 'react'; import { mount } from 'enzyme'; import { resetWarned } from 'rc-util/lib/warning'; +import React from 'react'; import Table from '../src'; describe('Table.Deprecated', () => { let errorSpy; beforeAll(() => { - errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); + errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {}); }); beforeEach(() => { @@ -34,7 +34,7 @@ describe('Table.Deprecated', () => { removedProp => { it(`warning for '${removedProp}'`, () => { const props = { - [removedProp]: jest.fn(), + [removedProp]: vi.fn(), }; mount(); diff --git a/tests/ExpandRow.spec.js b/tests/ExpandRow.spec.jsx similarity index 96% rename from tests/ExpandRow.spec.js rename to tests/ExpandRow.spec.jsx index 7dbb9593d..0fd701f7f 100644 --- a/tests/ExpandRow.spec.js +++ b/tests/ExpandRow.spec.jsx @@ -1,8 +1,8 @@ -import React from 'react'; import { mount } from 'enzyme'; -import { act } from 'react-dom/test-utils'; -import { resetWarned } from 'rc-util/lib/warning'; import { spyElementPrototype } from 'rc-util/lib/test/domHook'; +import { resetWarned } from 'rc-util/lib/warning'; +import React from 'react'; +import { act } from 'react-dom/test-utils'; import Table from '../src'; describe('Table.Expand', () => { @@ -22,7 +22,7 @@ describe('Table.Expand', () => { it('renders expand row correctly', () => { resetWarned(); - const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); + const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {}); const wrapper = mount(createTable({ expandedRowRender })); expect(wrapper.find('tbody tr')).toHaveLength(2); expect(errorSpy).toHaveBeenCalledWith( @@ -32,7 +32,7 @@ describe('Table.Expand', () => { }); it('pass proper parameters to expandedRowRender', () => { - const rowRender = jest.fn(() =>
expanded row
); + const rowRender = vi.fn(() =>
expanded row
); const expandableProps = props => ({ expandable: { expandedRowRender: rowRender, ...props } }); const wrapper = mount(createTable(expandableProps())); wrapper.setProps(expandableProps({ expandedRowKeys: [0] })); @@ -232,7 +232,7 @@ describe('Table.Expand', () => { describe('config expand column index', () => { it('not show EXPAND_COLUMN if expandable is false', () => { resetWarned(); - const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); + const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {}); const wrapper = mount( createTable({ @@ -250,7 +250,7 @@ describe('Table.Expand', () => { it('renders expand icon to the specify column', () => { resetWarned(); - const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); + const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {}); const wrapper = mount( createTable({ @@ -287,7 +287,7 @@ describe('Table.Expand', () => { it('de-duplicate of EXPAND_COLUMN', () => { resetWarned(); - const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); + const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {}); const wrapper = mount( createTable({ @@ -400,7 +400,7 @@ describe('Table.Expand', () => { }); it('renders expend row class correctly', () => { - const expandedRowClassName = jest.fn().mockReturnValue('expand-row-test-class-name'); + const expandedRowClassName = vi.fn().mockReturnValue('expand-row-test-class-name'); const wrapper = mount( createTable({ expandable: { @@ -431,7 +431,7 @@ describe('Table.Expand', () => { }); it('fires expand change event', () => { - const onExpand = jest.fn(); + const onExpand = vi.fn(); const wrapper = mount( createTable({ expandable: { @@ -448,7 +448,7 @@ describe('Table.Expand', () => { }); it('fires onExpandedRowsChange event', () => { - const onExpandedRowsChange = jest.fn(); + const onExpandedRowsChange = vi.fn(); const wrapper = mount( createTable({ expandedRowRender, @@ -473,7 +473,7 @@ describe('Table.Expand', () => { }); it('expandRowByClick', () => { - const onExpand = jest.fn(); + const onExpand = vi.fn(); const wrapper = mount( createTable({ expandable: { @@ -533,7 +533,7 @@ describe('Table.Expand', () => { // https://github.com/ant-design/ant-design/issues/23894 it('should be collapsible when use `expandIcon` & `expandRowByClick`', () => { const data = [{ key: 0, name: 'Lucy', age: 27 }]; - const onExpand = jest.fn(); + const onExpand = vi.fn(); const wrapper = mount( createTable({ expandable: { @@ -561,7 +561,7 @@ describe('Table.Expand', () => { // https://github.com/ant-design/ant-design/issues/23894 it('should be collapsible when `expandRowByClick` without custom `expandIcon`', () => { const data = [{ key: 0, name: 'Lucy', age: 27 }]; - const onExpand = jest.fn(); + const onExpand = vi.fn(); const wrapper = mount( createTable({ expandable: { @@ -582,7 +582,7 @@ describe('Table.Expand', () => { it('should be collapsible when `expandRowByClick` with custom `expandIcon` and event.stopPropagation', () => { const data = [{ key: 0, name: 'Lucy', age: 27 }]; - const onExpand = jest.fn(); + const onExpand = vi.fn(); const wrapper = mount( createTable({ expandable: { @@ -612,7 +612,7 @@ describe('Table.Expand', () => { it('support invalid expandIcon', () => { const data = [{ key: 0, name: 'Lucy', age: 27 }]; - const onExpand = jest.fn(); + const onExpand = vi.fn(); const wrapper = mount( createTable({ expandable: { @@ -629,7 +629,7 @@ describe('Table.Expand', () => { it('warning for use `expandedRowRender` and nested table in the same time', () => { resetWarned(); - const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); + const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {}); mount(createTable({ expandedRowRender, data: [{ children: [] }] })); expect(errorSpy).toHaveBeenCalledWith( 'Warning: `expandedRowRender` should not use with nested Table', diff --git a/tests/FixedColumn-IE.spec.js b/tests/FixedColumn-IE.spec.jsx similarity index 95% rename from tests/FixedColumn-IE.spec.js rename to tests/FixedColumn-IE.spec.jsx index 6c3565939..feff1ca19 100644 --- a/tests/FixedColumn-IE.spec.js +++ b/tests/FixedColumn-IE.spec.jsx @@ -1,12 +1,12 @@ -import React from 'react'; import { mount } from 'enzyme'; -import { act } from 'react-dom/test-utils'; import { spyElementPrototype } from 'rc-util/lib/test/domHook'; +import React from 'react'; +import { act } from 'react-dom/test-utils'; // eslint-disable-next-line @typescript-eslint/no-unused-vars -import Table from '../src'; import RcResizeObserver from 'rc-resize-observer'; +import Table from '../src'; -jest.mock('rc-util/lib/Dom/styleChecker', () => { +vi.mock('rc-util/lib/Dom/styleChecker', () => { return { isStyleSupport: (name, val) => val !== 'sticky', }; @@ -42,7 +42,7 @@ describe('Table.FixedColumn', () => { const data = [{ a: '123', b: 'xxxxxxxx', d: 3, key: '1' }]; it('not sticky', async () => { - jest.useFakeTimers(); + vi.useFakeTimers(); const wrapper = mount(
); act(() => { @@ -59,7 +59,7 @@ describe('Table.FixedColumn', () => { }); await act(async () => { - jest.runAllTimers(); + vi.runAllTimers(); await Promise.resolve(); wrapper.update(); }); diff --git a/tests/FixedColumn.spec.js b/tests/FixedColumn.spec.jsx similarity index 97% rename from tests/FixedColumn.spec.js rename to tests/FixedColumn.spec.jsx index 18eb60451..a0f7eb47a 100644 --- a/tests/FixedColumn.spec.js +++ b/tests/FixedColumn.spec.jsx @@ -3,13 +3,13 @@ import RcResizeObserver from 'rc-resize-observer'; import { spyElementPrototypes } from 'rc-util/lib/test/domHook'; import { resetWarned } from 'rc-util/lib/warning'; import { act } from 'react-dom/test-utils'; -import { safeAct } from './utils'; import Table from '../src'; +import { safeAct } from './utils'; describe('Table.FixedColumn', () => { let domSpy; beforeEach(() => { - jest.useFakeTimers(); + vi.useFakeTimers(); }); beforeAll(() => { domSpy = spyElementPrototypes(HTMLElement, { @@ -70,7 +70,7 @@ describe('Table.FixedColumn', () => { { name: 'without data', data: [] }, ].forEach(({ name, data: testData }) => { it(`${scrollName} - ${name}`, async () => { - jest.useFakeTimers(); + vi.useFakeTimers(); const wrapper = mount(
); act(() => { @@ -91,7 +91,7 @@ describe('Table.FixedColumn', () => { }); await safeAct(wrapper); expect(wrapper.render()).toMatchSnapshot(); - jest.useRealTimers(); + vi.useRealTimers(); }); }); }); @@ -107,7 +107,7 @@ describe('Table.FixedColumn', () => { scroll={{ x: 'max-content' }} />, ); - + await safeAct(wrapper); expect(wrapper.find('colgroup').render()).toMatchSnapshot(); @@ -193,7 +193,7 @@ describe('Table.FixedColumn', () => { let errorSpy; beforeAll(() => { - errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); + errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {}); }); beforeEach(() => { diff --git a/tests/FixedHeader.spec.js b/tests/FixedHeader.spec.jsx similarity index 95% rename from tests/FixedHeader.spec.js rename to tests/FixedHeader.spec.jsx index 842c9f45e..adb4ed885 100644 --- a/tests/FixedHeader.spec.js +++ b/tests/FixedHeader.spec.jsx @@ -3,8 +3,8 @@ import RcResizeObserver from 'rc-resize-observer'; import { spyElementPrototype } from 'rc-util/lib/test/domHook'; import React from 'react'; import { act } from 'react-dom/test-utils'; -import { safeAct } from './utils'; import Table, { INTERNAL_COL_DEFINE } from '../src'; +import { safeAct } from './utils'; describe('Table.FixedHeader', () => { let domSpy; @@ -17,7 +17,7 @@ describe('Table.FixedHeader', () => { }); beforeEach(() => { - jest.useFakeTimers(); + vi.useFakeTimers(); visible = true; }); @@ -58,7 +58,6 @@ describe('Table.FixedHeader', () => { expect(wrapper.find('.rc-table-header table').props().style.visibility).toBeFalsy(); - expect(); expect(wrapper.find('colgroup col').at(0).props().style.width).toEqual(100); expect(wrapper.find('colgroup col').at(1).props().style.width).toEqual(200); expect(wrapper.find('colgroup col').at(2).props().style.width).toEqual(0); @@ -70,7 +69,7 @@ describe('Table.FixedHeader', () => { expect(wrapper.find('colgroup col').at(0).props().style.width).toEqual(200); expect(wrapper.find('colgroup col').at(1).props().style.width).toEqual(100); - jest.useRealTimers(); + vi.useRealTimers(); }); it('INTERNAL_COL_DEFINE', async () => { @@ -121,7 +120,7 @@ describe('Table.FixedHeader', () => { }} />, ); - + await safeAct(wrapper); expect(wrapper.find('.rc-table-header table').props().style).toEqual( expect.objectContaining({ visibility: null }), @@ -190,7 +189,7 @@ describe('Table.FixedHeader', () => { ]); act(() => { - jest.runAllTimers(); + vi.runAllTimers(); wrapper.update(); }); @@ -198,7 +197,7 @@ describe('Table.FixedHeader', () => { expect.objectContaining({ width: 93 }), ); - jest.useRealTimers(); + vi.useRealTimers(); }); it('do not mask as ant-table-cell-fix-left-last in nested table parent cell', async () => { @@ -247,16 +246,11 @@ describe('Table.FixedHeader', () => { name: 'Jack1', }, ]; - const wrapper = mount( -
, - ); + const wrapper = mount(
); await safeAct(wrapper); expect(wrapper.find('td').at(9).props().className).toContain('rc-table-cell-fix-left-last'); - expect(wrapper.find('th').first().props().className).not.toContain('rc-table-cell-fix-left-last'); - + expect(wrapper.find('th').first().props().className).not.toContain( + 'rc-table-cell-fix-left-last', + ); }); }); diff --git a/tests/GroupingColumns.spec.js b/tests/GroupingColumns.spec.jsx similarity index 100% rename from tests/GroupingColumns.spec.js rename to tests/GroupingColumns.spec.jsx index 2f69d74e5..7300265f7 100644 --- a/tests/GroupingColumns.spec.js +++ b/tests/GroupingColumns.spec.jsx @@ -1,5 +1,5 @@ -import React from 'react'; import { mount } from 'enzyme'; +import React from 'react'; import Table from '../src'; describe('Table with grouping columns', () => { diff --git a/tests/Hover.spec.tsx b/tests/Hover.spec.tsx index 7f49160c3..01162e7b1 100644 --- a/tests/Hover.spec.tsx +++ b/tests/Hover.spec.tsx @@ -1,7 +1,7 @@ -import React from 'react'; import { mount } from 'enzyme'; -import { resetWarned } from 'rc-util/lib/warning'; import toArray from 'rc-util/lib/Children/toArray'; +import { resetWarned } from 'rc-util/lib/warning'; +import React from 'react'; import Table from '../src'; import type { TableProps } from '../src/Table'; @@ -41,7 +41,7 @@ describe('Table.Hover', () => { it('warning if use `render` for rowSpan', () => { resetWarned(); - const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); + const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {}); const wrapper = mount( createTable({ diff --git a/tests/Internal.spec.js b/tests/Internal.spec.jsx similarity index 100% rename from tests/Internal.spec.js rename to tests/Internal.spec.jsx diff --git a/tests/Scroll.spec.js b/tests/Scroll.spec.jsx similarity index 91% rename from tests/Scroll.spec.js rename to tests/Scroll.spec.jsx index c5e243658..a4511d6cb 100644 --- a/tests/Scroll.spec.js +++ b/tests/Scroll.spec.jsx @@ -1,11 +1,14 @@ -import React from 'react'; import { mount } from 'enzyme'; -import { act } from 'react-dom/test-utils'; import { spyElementPrototypes } from 'rc-util/lib/test/domHook'; +import React from 'react'; +import { act } from 'react-dom/test-utils'; import Table from '../src'; describe('Table.Scroll', () => { - const data = [{ key: 'key0', name: 'Lucy' }, { key: 'key1', name: 'Jack' }]; + const data = [ + { key: 'key0', name: 'Lucy' }, + { key: 'key1', name: 'Jack' }, + ]; const createTable = props => { const columns = [{ title: 'Name', dataIndex: 'name', key: 'name' }]; @@ -36,14 +39,14 @@ describe('Table.Scroll', () => { }); it('fire scroll event', () => { - jest.useFakeTimers(); + vi.useFakeTimers(); let scrollLeft = 0; let scrollTop = 0; - const setScrollLeft = jest.fn((_, val) => { + const setScrollLeft = vi.fn((_, val) => { scrollLeft = val; }); - const setScrollTop = jest.fn((_, val) => { + const setScrollTop = vi.fn((_, val) => { scrollTop = val; }); @@ -85,7 +88,7 @@ describe('Table.Scroll', () => { />, ); - jest.runAllTimers(); + vi.runAllTimers(); // Use `onScroll` directly since simulate not support `currentTarget` act(() => { const headerDiv = wrapper.find('div.rc-table-header').instance(); @@ -96,7 +99,7 @@ describe('Table.Scroll', () => { }); headerDiv.dispatchEvent(wheelEvent); - jest.runAllTimers(); + vi.runAllTimers(); }); expect(setScrollLeft).toHaveBeenCalledWith(undefined, 10); @@ -114,11 +117,11 @@ describe('Table.Scroll', () => { }, }); }); - jest.runAllTimers(); + vi.runAllTimers(); expect(setScrollLeft).toHaveBeenCalledWith(undefined, 33); setScrollLeft.mockReset(); domSpy.mockRestore(); - jest.useRealTimers(); + vi.useRealTimers(); }); }); diff --git a/tests/Sticky.spec.js b/tests/Sticky.spec.jsx similarity index 96% rename from tests/Sticky.spec.js rename to tests/Sticky.spec.jsx index f1ccbda2c..34cc1cb8d 100644 --- a/tests/Sticky.spec.js +++ b/tests/Sticky.spec.jsx @@ -1,13 +1,13 @@ -import React from 'react'; -import { act } from 'react-dom/test-utils'; import { mount } from 'enzyme'; import { spyElementPrototypes } from 'rc-util/lib/test/domHook'; +import React from 'react'; +import { act } from 'react-dom/test-utils'; import Table from '../src'; import { safeAct } from './utils'; describe('Table.Sticky', () => { beforeEach(() => { - jest.useFakeTimers(); + vi.useFakeTimers(); }); it('Sticky Header', async () => { const col1 = { dataIndex: 'light', width: 100 }; @@ -53,7 +53,7 @@ describe('Table.Sticky', () => { top: 10, }); - jest.useRealTimers(); + vi.useRealTimers(); }); it('Sticky scroll', async () => { @@ -120,7 +120,7 @@ describe('Table.Sticky', () => { ); await act(async () => { - jest.runAllTimers(); + vi.runAllTimers(); await Promise.resolve(); }); @@ -133,7 +133,7 @@ describe('Table.Sticky', () => { await act(async () => { global.dispatchEvent(resizeEvent); - jest.runAllTimers(); + vi.runAllTimers(); await Promise.resolve(); wrapper.update(); }); @@ -143,12 +143,12 @@ describe('Table.Sticky', () => { await act(async () => { global.innerHeight = oldInnerHeight; global.dispatchEvent(resizeEvent); - jest.runAllTimers(); + vi.runAllTimers(); await Promise.resolve(); wrapper.update(); }); - const mockFn = jest.fn(); + const mockFn = vi.fn(); wrapper .find('.rc-table-sticky-scroll-bar') @@ -165,7 +165,7 @@ describe('Table.Sticky', () => { await act(async () => { document.body.dispatchEvent(mousemoveEvent); - jest.runAllTimers(); + vi.runAllTimers(); await Promise.resolve(); wrapper.update(); }); @@ -179,7 +179,7 @@ describe('Table.Sticky', () => { mousemoveEvent.pageX = -50; document.body.dispatchEvent(mousemoveEvent); - jest.runAllTimers(); + vi.runAllTimers(); await Promise.resolve(); wrapper.update(); }); @@ -193,7 +193,7 @@ describe('Table.Sticky', () => { mousemoveEvent.buttons = 0; document.body.dispatchEvent(mousemoveEvent); - jest.runAllTimers(); + vi.runAllTimers(); await Promise.resolve(); wrapper.update(); }); @@ -209,11 +209,10 @@ describe('Table.Sticky', () => { window.pageYOffset = 0; mockFn.mockRestore(); domSpy.mockRestore(); - jest.useRealTimers(); + vi.useRealTimers(); }); it('Sticky Header with border classname', async () => { - const TableDemo = props => { return (
{ }); expect(wrapper.find('.rc-table-cell-fix-sticky')).not.toBe(undefined); - jest.useRealTimers(); + vi.useRealTimers(); }); it('Sticky Header with scroll-y', async () => { - const TableDemo = props => { return (
{ right: 15, }); - jest.useRealTimers(); + vi.useRealTimers(); }); it('Sticky scroll with getContainer', async () => { - window.pageYOffset = 900; document.documentElement.scrollTop = 200; const container = document.createElement('ol'); @@ -393,7 +390,7 @@ describe('Table.Sticky', () => { ); await act(async () => { - jest.runAllTimers(); + vi.runAllTimers(); await Promise.resolve(); }); @@ -405,7 +402,7 @@ describe('Table.Sticky', () => { transform: 'translate3d(0px, 0, 0)', }); - const mockFn = jest.fn(); + const mockFn = vi.fn(); wrapper .find('.rc-table-sticky-scroll-bar') @@ -420,7 +417,7 @@ describe('Table.Sticky', () => { await act(async () => { document.body.dispatchEvent(mousemoveEvent); - jest.runAllTimers(); + vi.runAllTimers(); await Promise.resolve(); wrapper.update(); }); @@ -436,6 +433,6 @@ describe('Table.Sticky', () => { domSpy.mockRestore(); sectionSpy.mockRestore(); mockFn.mockRestore(); - jest.useRealTimers(); + vi.useRealTimers(); }); }); diff --git a/tests/Summary.spec.tsx b/tests/Summary.spec.tsx index 826a80c64..61d9b9a6c 100644 --- a/tests/Summary.spec.tsx +++ b/tests/Summary.spec.tsx @@ -54,7 +54,7 @@ describe('Table.Summary', () => { }); it('summary row click', async () => { - const onClick = jest.fn(); + const onClick = vi.fn(); const wrapper = mount(
{ describe('dataIndex', () => { it("pass record to render when it's falsy", () => { [null, undefined, '', []].forEach(dataIndex => { - const cellRender = jest.fn(); + const cellRender = vi.fn(); const columns = [ { title: 'Name', @@ -504,7 +504,7 @@ describe('Table.Basic', () => { }); it('shows error if no rowKey specify', () => { - const spy = jest.spyOn(console, 'error').mockImplementation(() => {}); + const spy = vi.spyOn(console, 'error').mockImplementation(() => {}); const localData = [{ name: 'Lucy' }, { name: 'Jack' }]; mount(createTable({ data: localData })); expect(spy.mock.calls[0][0]).toMatch( @@ -595,7 +595,7 @@ describe('Table.Basic', () => { }); it('renders onHeaderRow correctly', () => { - const onHeaderRow = jest.fn((columns, index) => ({ + const onHeaderRow = vi.fn((columns, index) => ({ id: `header-row-${index}`, })); const wrapper = mount(createTable({ onHeaderRow })); @@ -666,7 +666,7 @@ describe('Table.Basic', () => { describe('scroll content', () => { it('with scroll', () => { resetWarned(); - const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); + const errSpy = vi.spyOn(console, 'error').mockImplementation(() => {}); const wrapper = mount( createTable({ columns: [{ dataIndex: 'a' }, { dataIndex: 'b', width: 903 }], @@ -686,7 +686,7 @@ describe('Table.Basic', () => { it('without scroll', () => { resetWarned(); - const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); + const errSpy = vi.spyOn(console, 'error').mockImplementation(() => {}); mount( createTable({ components: { @@ -703,7 +703,7 @@ describe('Table.Basic', () => { it('without warning - columns is empty', () => { resetWarned(); - const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); + const errSpy = vi.spyOn(console, 'error').mockImplementation(() => {}); mount( createTable({ columns: [], @@ -775,7 +775,7 @@ describe('Table.Basic', () => { let spy; beforeAll(() => { - spy = jest.spyOn(console, 'error').mockImplementation(() => {}); + spy = vi.spyOn(console, 'error').mockImplementation(() => {}); }); afterEach(() => { @@ -787,7 +787,7 @@ describe('Table.Basic', () => { }); it('fires row click event', () => { - const onClick = jest.fn(); + const onClick = vi.fn(); const wrapper = mount(createTable({ onRow: () => ({ onClick }) })); const tr = wrapper.find('tbody tr').first(); @@ -800,7 +800,7 @@ describe('Table.Basic', () => { }); it('fires double row click event', () => { - const onDoubleClick = jest.fn(); + const onDoubleClick = vi.fn(); const wrapper = mount(createTable({ onRow: () => ({ onDoubleClick }) })); const tr = wrapper.find('tbody tr').first(); @@ -813,7 +813,7 @@ describe('Table.Basic', () => { }); it('fires row contextmenu event', () => { - const onContextMenu = jest.fn(); + const onContextMenu = vi.fn(); const wrapper = mount(createTable({ onRow: () => ({ onContextMenu }) })); const tr = wrapper.find('tbody tr').first(); @@ -826,7 +826,7 @@ describe('Table.Basic', () => { }); it('fires onRowMouseEnter', () => { - const onMouseEnter = jest.fn(); + const onMouseEnter = vi.fn(); const wrapper = mount( createTable({ onRow: () => ({ onMouseEnter }), @@ -844,7 +844,7 @@ describe('Table.Basic', () => { }); it('fires onRowMouseLeave', () => { - const onMouseLeave = jest.fn(); + const onMouseLeave = vi.fn(); const wrapper = mount( createTable({ onRow: () => ({ onMouseLeave }), @@ -1055,7 +1055,7 @@ describe('Table.Basic', () => { }); it('not block nest children', () => { - const onExpandedRowsChange = jest.fn(); + const onExpandedRowsChange = vi.fn(); const wrapper = mount(
-
-
-
- - - - - - - - - - - - - - - - - - - - - -
- Name - - Age -
- - - Lucy - - 27 -
- - - Jim - - 1 -
- - - Jack - - 28 -
- - - -`; - -exports[`Table.Expand does not crash if scroll is not set 1`] = ` -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - Name - - Age - - Gender -
- - - Lucy - - 27 - - F -
- - - Jack - - 28 - - M -
-
-
-
-`; - -exports[`Table.Expand does not crash if scroll is not set 2`] = ` -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - Name - - Age - - Gender -
- - - Lucy - - 27 - - F -
- - - Jack - - 28 - - M -
-
-
-
-`; - -exports[`Table.Expand not use nest when children is invalidate 1`] = ` -
-
-
- - - - - - - - - - - - - - - - - - - - - - -
- Name - - Age -
- Jack - - 28 -
- Jack - - 28 -
- Jack - - 28 -
-
-
-
-`; - -exports[`Table.Expand renders fixed column correctly work 1`] = ` -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - Name - - Age - - Gender -
- - - Lucy - - 27 - - F -
-
-

- extra data -

-
-
- - - Jack - - 28 - - M -
-
-

- extra data -

-
-
-
-
-
-`; - -exports[`Table.Expand renders tree row correctly 1`] = ` -
-
-
- - - - - - - - - - - - - - - - - - - - - - -
- Name - - Age -
- - - Lucy - - 27 -
- - - Jim - - 1 -
- - - Jack - - 28 -
-
-
-
-`; - -exports[`Table.Expand renders tree row correctly with different children 1`] = ` -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Name - - Age -
- - - Lucy - - 27 -
- - - Jack - - 28 -
- - - Jack - - 28 -
- - - Jack - - 28 -
- - - Jack - - 28 -
- - - Jack - - 28 -
-
-
-
-`; - -exports[`Table.Expand work in expandable fix 1`] = ` -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - Name - - Age - - Gender -
- - - Lucy - - 27 - - F -
- - - Jack - - 28 - - M -
-
-
-
-`; - -exports[`Table.Expand work in expandable fix 2`] = ` -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Name - - Age - - Gender - -
- Lucy - - 27 - - F - - -
- Jack - - 28 - - M - - -
-
-
-
-`; diff --git a/tests/__snapshots__/ExpandRow.spec.jsx.snap b/tests/__snapshots__/ExpandRow.spec.jsx.snap new file mode 100644 index 000000000..96f841d8f --- /dev/null +++ b/tests/__snapshots__/ExpandRow.spec.jsx.snap @@ -0,0 +1,1554 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`Table.Expand > childrenColumnName 1`] = ` +LoadedCheerio { + "0":
+
+
+ + + + + + + + + + + + + + + + + + + + + + +
+ Name + + Age +
+ + + Lucy + + 27 +
+ + + Jim + + 1 +
+ + + Jack + + 28 +
+
+
+
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + + + + , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.Expand > does not crash if scroll is not set 1`] = ` +LoadedCheerio { + "0":
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + Name + + Age + + Gender +
+ + + Lucy + + 27 + + F +
+ + + Jack + + 28 + + M +
+
+
+
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + + + + , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.Expand > does not crash if scroll is not set 2`] = ` +LoadedCheerio { + "0":
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + Name + + Age + + Gender +
+ + + Lucy + + 27 + + F +
+ + + Jack + + 28 + + M +
+
+
+
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + + + + , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.Expand > not use nest when children is invalidate 1`] = ` +LoadedCheerio { + "0":
+
+
+ + + + + + + + + + + + + + + + + + + + + + +
+ Name + + Age +
+ Jack + + 28 +
+ Jack + + 28 +
+ Jack + + 28 +
+
+
+
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + + + + , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.Expand > renders fixed column correctly > work 1`] = ` +LoadedCheerio { + "0":
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + Name + + Age + + Gender +
+ + + Lucy + + 27 + + F +
+
+

+ extra data +

+
+
+ + + Jack + + 28 + + M +
+
+

+ extra data +

+
+
+
+
+
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + + + + , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.Expand > renders tree row correctly 1`] = ` +LoadedCheerio { + "0":
+
+
+ + + + + + + + + + + + + + + + + + + + + + +
+ Name + + Age +
+ + + Lucy + + 27 +
+ + + Jim + + 1 +
+ + + Jack + + 28 +
+
+
+
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + + + + , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.Expand > renders tree row correctly with different children 1`] = ` +LoadedCheerio { + "0":
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Name + + Age +
+ + + Lucy + + 27 +
+ + + Jack + + 28 +
+ + + Jack + + 28 +
+ + + Jack + + 28 +
+ + + Jack + + 28 +
+ + + Jack + + 28 +
+
+
+
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + + + + , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.Expand > work in expandable fix 1`] = ` +LoadedCheerio { + "0":
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + Name + + Age + + Gender +
+ + + Lucy + + 27 + + F +
+ + + Jack + + 28 + + M +
+
+
+
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + + + + , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.Expand > work in expandable fix 2`] = ` +LoadedCheerio { + "0":
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Name + + Age + + Gender + +
+ Lucy + + 27 + + F + + +
+ Jack + + 28 + + M + + +
+
+
+
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + + + + , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; diff --git a/tests/__snapshots__/FixedColumn.spec.js.snap b/tests/__snapshots__/FixedColumn.spec.js.snap deleted file mode 100644 index 99648e662..000000000 --- a/tests/__snapshots__/FixedColumn.spec.js.snap +++ /dev/null @@ -1,2965 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Table.FixedColumn fixed column renders correctly RTL 1`] = ` -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- title1 - - title2 - - title3 - - title4 - - title5 - - title6 - - title7 - - title8 - - title9 - - title10 - - title11 - - title12 -
- 123 - - - 1111 - - - - xxxxxxxx - - xxxxxxxx - - xxxxxxxx - - xxxxxxxx - - xxxxxxxx - - xxxxxxxx - - xxxxxxxx - - xxxxxxxx - - xxxxxxxx -
- cdd - - - 1111 - - - - edd12221 - - edd12221 - - edd12221 - - edd12221 - - edd12221 - - edd12221 - - edd12221 - - edd12221 - - edd12221 -
- 133 - - - 1111 - - - edd12221 - - - - - - - - - -
- 133 - - - 1111 - - - edd12221 - - - - - - - - - -
- 133 - - - 1111 - - - edd12221 - - - - - - - - - -
- 133 - - - 1111 - - - edd12221 - - - - - - - - - -
- 133 - - - 1111 - - - edd12221 - - - - - - - - - -
- 133 - - - 1111 - - - edd12221 - - - - - - - - - -
- 133 - - - 1111 - - - edd12221 - - - - - - - - - -
-
-
-
-`; - -exports[`Table.FixedColumn renders correctly all column has width should use it 1`] = ` - - - - -`; - -exports[`Table.FixedColumn renders correctly scrollX - with data 1`] = ` -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- title1 - - - title2 - - - title3 - - title4 - - title5 - - title6 - - title7 - - title8 - - title9 - - title10 - - title11 - - title12 -
- 123 - - - - 1111 - - - - - xxxxxxxx - - xxxxxxxx - - xxxxxxxx - - xxxxxxxx - - xxxxxxxx - - xxxxxxxx - - xxxxxxxx - - xxxxxxxx - - xxxxxxxx -
- cdd - - - - 1111 - - - - - edd12221 - - edd12221 - - edd12221 - - edd12221 - - edd12221 - - edd12221 - - edd12221 - - edd12221 - - edd12221 -
- 133 - - - - 1111 - - - - edd12221 - - - - - - - - - -
- 133 - - - - 1111 - - - - edd12221 - - - - - - - - - -
- 133 - - - - 1111 - - - - edd12221 - - - - - - - - - -
- 133 - - - - 1111 - - - - edd12221 - - - - - - - - - -
- 133 - - - - 1111 - - - - edd12221 - - - - - - - - - -
- 133 - - - - 1111 - - - - edd12221 - - - - - - - - - -
- 133 - - - - 1111 - - - - edd12221 - - - - - - - - - -
-
-
-
-`; - -exports[`Table.FixedColumn renders correctly scrollX - without data 1`] = ` -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- title1 - - - title2 - - - title3 - - title4 - - title5 - - title6 - - title7 - - title8 - - title9 - - title10 - - title11 - - title12 -
-
- No Data -
-
-
-
-
-`; - -exports[`Table.FixedColumn renders correctly scrollXY - with data 1`] = ` -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- title1 - - - title2 - - - title3 - - title4 - - title5 - - title6 - - title7 - - title8 - - title9 - - title10 - - title11 - - title12 - -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- 123 - - - - 1111 - - - - - xxxxxxxx - - xxxxxxxx - - xxxxxxxx - - xxxxxxxx - - xxxxxxxx - - xxxxxxxx - - xxxxxxxx - - xxxxxxxx - - xxxxxxxx -
- cdd - - - - 1111 - - - - - edd12221 - - edd12221 - - edd12221 - - edd12221 - - edd12221 - - edd12221 - - edd12221 - - edd12221 - - edd12221 -
- 133 - - - - 1111 - - - - edd12221 - - - - - - - - - -
- 133 - - - - 1111 - - - - edd12221 - - - - - - - - - -
- 133 - - - - 1111 - - - - edd12221 - - - - - - - - - -
- 133 - - - - 1111 - - - - edd12221 - - - - - - - - - -
- 133 - - - - 1111 - - - - edd12221 - - - - - - - - - -
- 133 - - - - 1111 - - - - edd12221 - - - - - - - - - -
- 133 - - - - 1111 - - - - edd12221 - - - - - - - - - -
-
-
-
-`; - -exports[`Table.FixedColumn renders correctly scrollXY - without data 1`] = ` -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- title1 - - - title2 - - - title3 - - title4 - - title5 - - title6 - - title7 - - title8 - - title9 - - title10 - - title11 - - title12 - -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- No Data -
-
-
-
-
-`; diff --git a/tests/__snapshots__/FixedColumn.spec.jsx.snap b/tests/__snapshots__/FixedColumn.spec.jsx.snap new file mode 100644 index 000000000..249dfc2ef --- /dev/null +++ b/tests/__snapshots__/FixedColumn.spec.jsx.snap @@ -0,0 +1,3145 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`Table.FixedColumn > fixed column renders correctly RTL 1`] = ` +LoadedCheerio { + "0":
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ title1 + + title2 + + title3 + + title4 + + title5 + + title6 + + title7 + + title8 + + title9 + + title10 + + title11 + + title12 +
+ 123 + + + 1111 + + + + xxxxxxxx + + xxxxxxxx + + xxxxxxxx + + xxxxxxxx + + xxxxxxxx + + xxxxxxxx + + xxxxxxxx + + xxxxxxxx + + xxxxxxxx +
+ cdd + + + 1111 + + + + edd12221 + + edd12221 + + edd12221 + + edd12221 + + edd12221 + + edd12221 + + edd12221 + + edd12221 + + edd12221 +
+ 133 + + + 1111 + + + edd12221 + + + + + + + + + +
+ 133 + + + 1111 + + + edd12221 + + + + + + + + + +
+ 133 + + + 1111 + + + edd12221 + + + + + + + + + +
+ 133 + + + 1111 + + + edd12221 + + + + + + + + + +
+ 133 + + + 1111 + + + edd12221 + + + + + + + + + +
+ 133 + + + 1111 + + + edd12221 + + + + + + + + + +
+ 133 + + + 1111 + + + edd12221 + + + + + + + + + +
+
+
+
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + + + + , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.FixedColumn > renders correctly > all column has width should use it 1`] = ` +LoadedCheerio { + "0": + + + , + "_root": LoadedCheerio { + "0": Document { + "children": [ + + + + , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.FixedColumn > renders correctly > scrollX - with data 1`] = ` +LoadedCheerio { + "0":
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ title1 + + + title2 + + + title3 + + title4 + + title5 + + title6 + + title7 + + title8 + + title9 + + title10 + + title11 + + title12 +
+ 123 + + + + 1111 + + + + + xxxxxxxx + + xxxxxxxx + + xxxxxxxx + + xxxxxxxx + + xxxxxxxx + + xxxxxxxx + + xxxxxxxx + + xxxxxxxx + + xxxxxxxx +
+ cdd + + + + 1111 + + + + + edd12221 + + edd12221 + + edd12221 + + edd12221 + + edd12221 + + edd12221 + + edd12221 + + edd12221 + + edd12221 +
+ 133 + + + + 1111 + + + + edd12221 + + + + + + + + + +
+ 133 + + + + 1111 + + + + edd12221 + + + + + + + + + +
+ 133 + + + + 1111 + + + + edd12221 + + + + + + + + + +
+ 133 + + + + 1111 + + + + edd12221 + + + + + + + + + +
+ 133 + + + + 1111 + + + + edd12221 + + + + + + + + + +
+ 133 + + + + 1111 + + + + edd12221 + + + + + + + + + +
+ 133 + + + + 1111 + + + + edd12221 + + + + + + + + + +
+
+
+
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + + + + , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.FixedColumn > renders correctly > scrollX - without data 1`] = ` +LoadedCheerio { + "0":
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ title1 + + + title2 + + + title3 + + title4 + + title5 + + title6 + + title7 + + title8 + + title9 + + title10 + + title11 + + title12 +
+
+ No Data +
+
+
+
+
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + + + + , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.FixedColumn > renders correctly > scrollXY - with data 1`] = ` +LoadedCheerio { + "0":
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ title1 + + + title2 + + + title3 + + title4 + + title5 + + title6 + + title7 + + title8 + + title9 + + title10 + + title11 + + title12 + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ 123 + + + + 1111 + + + + + xxxxxxxx + + xxxxxxxx + + xxxxxxxx + + xxxxxxxx + + xxxxxxxx + + xxxxxxxx + + xxxxxxxx + + xxxxxxxx + + xxxxxxxx +
+ cdd + + + + 1111 + + + + + edd12221 + + edd12221 + + edd12221 + + edd12221 + + edd12221 + + edd12221 + + edd12221 + + edd12221 + + edd12221 +
+ 133 + + + + 1111 + + + + edd12221 + + + + + + + + + +
+ 133 + + + + 1111 + + + + edd12221 + + + + + + + + + +
+ 133 + + + + 1111 + + + + edd12221 + + + + + + + + + +
+ 133 + + + + 1111 + + + + edd12221 + + + + + + + + + +
+ 133 + + + + 1111 + + + + edd12221 + + + + + + + + + +
+ 133 + + + + 1111 + + + + edd12221 + + + + + + + + + +
+ 133 + + + + 1111 + + + + edd12221 + + + + + + + + + +
+
+
+
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + + + + , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.FixedColumn > renders correctly > scrollXY - without data 1`] = ` +LoadedCheerio { + "0":
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ title1 + + + title2 + + + title3 + + title4 + + title5 + + title6 + + title7 + + title8 + + title9 + + title10 + + title11 + + title12 + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ No Data +
+
+
+
+
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + + + + , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; diff --git a/tests/__snapshots__/Summary.spec.tsx.snap b/tests/__snapshots__/Summary.spec.tsx.snap index e72a20741..40aec2575 100644 --- a/tests/__snapshots__/Summary.spec.tsx.snap +++ b/tests/__snapshots__/Summary.spec.tsx.snap @@ -1,28 +1,58 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`Table.Summary support data type 1`] = ` - - - - Light - - - Bamboo - - - 112.5 - - - +exports[`Table.Summary > support data type 1`] = ` +LoadedCheerio { + "0": + + + Light + + + Bamboo + + + 112.5 + + + , + "_root": LoadedCheerio { + "0": Document { + "children": [ + + + + , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} `; diff --git a/tests/__snapshots__/Table.spec.js.snap b/tests/__snapshots__/Table.spec.js.snap deleted file mode 100644 index 13d03fd8c..000000000 --- a/tests/__snapshots__/Table.spec.js.snap +++ /dev/null @@ -1,918 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Table.Basic columns support JSX condition 1`] = ` -[ - , -
-
-
- - - - - - - - - - - - - - - - - - -
- title - - title3 -
- 2 - - 3 -
- 2 - - 3 -
-
-
-
, -] -`; - -exports[`Table.Basic custom components renders correctly 1`] = ` -
-
-
- - - - - - - - - - - - - - - -
- Name -
- Lucy -
- Jack -
-
-
-
-`; - -exports[`Table.Basic custom components renders fixed column and header correctly 1`] = ` -
-
-
- - - - - - - - - -
- Name - - Age - - Gender - -
-
-
- - - - - - - - - - - - - - -
- Lucy - - 27 - - F -
-
-
-
-`; - -exports[`Table.Basic custom components scroll content with scroll 1`] = ` -
-
-
- - - - - - - - - - -
- - -
-
-

- Bamboo -

-
-
-`; - -exports[`Table.Basic internal api transformColumns basic 1`] = ` -
-
-
- - - - - - - - - - - - - - - - - -
- before - - Name - - after -
- - Lucy - -
- - Jack - -
-
-
-
-`; - -exports[`Table.Basic renders colSpan correctly 1`] = ` -
-
-
- - - - - - - - - - - - - - - - -
- Name -
- John -
- Terry - - Garner -
-
-
-
-`; - -exports[`Table.Basic renders correctly RTL 1`] = ` -
-
-
- - - - - - - - - - - - - - - -
- Name -
- Lucy -
- Jack -
-
-
-
-`; - -exports[`Table.Basic renders correctly basic 1`] = ` -
-
-
- - - - - - - - - - - - - - - -
- Name -
- Lucy -
- Jack -
-
-
-
-`; - -exports[`Table.Basic renders correctly column children undefined 1`] = ` -
-
-
- - - - - - - - - - - - - - - - -
- 姓名 - - 年龄 -
- Lucy - -
- Jack - -
-
-
-
-`; - -exports[`Table.Basic renders correctly falsy columns 1`] = ` -
-
-
- - - - - - - - - - - - - - - -
- 姓名 -
- Lucy -
- Jack -
-
-
-
-`; - -exports[`Table.Basic renders correctly no columns 1`] = ` -
-
-
- - - - - - - - - - - - -
-
-
-
-
-
-
-`; - -exports[`Table.Basic renders rowSpan correctly 1`] = ` -
-
-
- - - - - - - - - - - - - - - - - -
- First Name - - Last Name -
- John - - Doe -
- Terry -
-
-
-
-`; - -exports[`Table.Basic should get scrollbar size 1`] = ` -
-
-
- - - - - - - - - - -
- Name - -
-
-
-
-`; - -exports[`Table.Basic syntactic sugar 1`] = ` -
-
-
- - - - - - - - - - - - - - - -
- total -
- Name -
- No Data -
-
-
-
-`; diff --git a/tests/__snapshots__/Table.spec.jsx.snap b/tests/__snapshots__/Table.spec.jsx.snap new file mode 100644 index 000000000..3dc5283f0 --- /dev/null +++ b/tests/__snapshots__/Table.spec.jsx.snap @@ -0,0 +1,1336 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`Table.Basic > columns support JSX condition 1`] = ` +LoadedCheerio { + "0": , + "1":
+
+
+ + + + + + + + + + + + + + + + + + +
+ title + + title3 +
+ 2 + + 3 +
+ 2 + + 3 +
+
+
+
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + + + + , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 2, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.Basic > custom components > renders correctly 1`] = ` +LoadedCheerio { + "0":
+
+
+ + + + + + + + + + + + + + + +
+ Name +
+ Lucy +
+ Jack +
+
+
+
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + + + + , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.Basic > custom components > renders fixed column and header correctly 1`] = ` +LoadedCheerio { + "0":
+
+
+ + + + + + + + + +
+ Name + + Age + + Gender + +
+
+
+ + + + + + + + + + + + + + +
+ Lucy + + 27 + + F +
+
+
+
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + + + + , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.Basic > custom components > scroll content > with scroll 1`] = ` +LoadedCheerio { + "0":
+
+
+ + + + + + + + + + +
+ + +
+
+

+ Bamboo +

+
+
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + + + + , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.Basic > internal api > transformColumns > basic 1`] = ` +LoadedCheerio { + "0":
+
+
+ + + + + + + + + + + + + + + + + +
+ before + + Name + + after +
+ + Lucy + +
+ + Jack + +
+
+
+
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + + + + , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.Basic > renders colSpan correctly 1`] = ` +LoadedCheerio { + "0":
+
+
+ + + + + + + + + + + + + + + + +
+ Name +
+ John +
+ Terry + + Garner +
+
+
+
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + + + + , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.Basic > renders correctly > RTL 1`] = ` +LoadedCheerio { + "0":
+
+
+ + + + + + + + + + + + + + + +
+ Name +
+ Lucy +
+ Jack +
+
+
+
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + + + + , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.Basic > renders correctly > basic 1`] = ` +LoadedCheerio { + "0":
+
+
+ + + + + + + + + + + + + + + +
+ Name +
+ Lucy +
+ Jack +
+
+
+
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + + + + , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.Basic > renders correctly > column children undefined 1`] = ` +LoadedCheerio { + "0":
+
+
+ + + + + + + + + + + + + + + + +
+ 姓名 + + 年龄 +
+ Lucy + +
+ Jack + +
+
+
+
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + + + + , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.Basic > renders correctly > falsy columns 1`] = ` +LoadedCheerio { + "0":
+
+
+ + + + + + + + + + + + + + + +
+ 姓名 +
+ Lucy +
+ Jack +
+
+
+
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + + + + , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.Basic > renders correctly > no columns 1`] = ` +LoadedCheerio { + "0":
+
+
+ + + + + + + + + + + + +
+
+
+
+
+
+
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + + + + , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.Basic > renders rowSpan correctly 1`] = ` +LoadedCheerio { + "0":
+
+
+ + + + + + + + + + + + + + + + + +
+ First Name + + Last Name +
+ John + + Doe +
+ Terry +
+
+
+
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + + + + , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.Basic > should get scrollbar size 1`] = ` +LoadedCheerio { + "0":
+
+
+ + + + + + + + + + +
+ Name + +
+
+
+
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + + + + , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.Basic > syntactic sugar 1`] = ` +LoadedCheerio { + "0":
+
+
+ + + + + + + + + + + + + + + +
+ total +
+ Name +
+ No Data +
+
+
+
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + + + + , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; diff --git a/tests/setup.js b/tests/setup.js deleted file mode 100644 index 154da504f..000000000 --- a/tests/setup.js +++ /dev/null @@ -1,7 +0,0 @@ -global.requestAnimationFrame = cb => setTimeout(cb, 0); -require('regenerator-runtime'); - -const Enzyme = require('enzyme'); -const Adapter = require('enzyme-adapter-react-16'); - -Enzyme.configure({ adapter: new Adapter() }); diff --git a/tests/setup.ts b/tests/setup.ts new file mode 100644 index 000000000..8597c2d9b --- /dev/null +++ b/tests/setup.ts @@ -0,0 +1,23 @@ +import type { TestingLibraryMatchers } from '@testing-library/jest-dom/matchers'; +import matchers from '@testing-library/jest-dom/matchers'; +import { expect } from 'vitest'; + +declare module 'vitest' { + interface Assertion extends jest.Matchers, TestingLibraryMatchers {} +} + +expect.extend(matchers); + +// https://github.com/nickcolley/jest-axe/issues/147#issuecomment-758804533 +const { getComputedStyle } = window; +window.getComputedStyle = elt => getComputedStyle(elt); + +global.requestAnimationFrame = cb => setTimeout(cb, 0); +require('regenerator-runtime'); + +vi.mock('rc-util/lib/getScrollBarSize'); + +const Enzyme = require('enzyme'); +const Adapter = require('enzyme-adapter-react-16'); + +Enzyme.configure({ adapter: new Adapter() }); diff --git a/tests/utils.js b/tests/utils.js index 8b6660ee0..ca13e158d 100644 --- a/tests/utils.js +++ b/tests/utils.js @@ -3,7 +3,7 @@ import { act } from 'react-dom/test-utils'; export function safeAct(wrapper, cb) { return act(async () => { cb && cb(); - jest.runAllTimers(); + vi.runAllTimers(); await Promise.resolve(); wrapper.update(); }); diff --git a/tsconfig.json b/tsconfig.json index 32b01dddc..857021e22 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,7 +11,8 @@ "@/*": ["src/*"], "@@/*": [".dumi/tmp/*"], "rc-table": ["src/index.ts"] - } + }, + "types": ["vitest/globals"] }, "include": [".dumi/**/*", ".dumirc.ts", "**/*.ts", "**/*.tsx"] } diff --git a/vitest.config.ts b/vitest.config.ts new file mode 100644 index 000000000..a61325b92 --- /dev/null +++ b/vitest.config.ts @@ -0,0 +1,13 @@ +import { defineConfig } from 'vitest/config'; + +export default defineConfig({ + esbuild: { + jsx: 'automatic', + }, + test: { + include: ['**/tests/*.spec.*'], + globals: true, + setupFiles: './tests/setup.ts', + environment: 'jsdom', + }, +});