import { mount } from 'enzyme'; import React from 'react'; import { act } from 'react-dom/test-utils'; import ProTable from '@ant-design/pro-table'; import { getFetchData } from './demo'; import { waitForComponentToPaint } from '../util'; describe('BasicTable Search', () => { const LINE_STR_COUNT = 20; // Mock offsetHeight // @ts-expect-error const originOffsetHeight = Object.getOwnPropertyDescriptor( HTMLElement.prototype, 'offsetHeight', ).get; Object.defineProperty(HTMLElement.prototype, 'offsetHeight', { get() { let html = this.innerHTML; html = html.replace(/<[^>]*>/g, ''); const lines = Math.ceil(html.length / LINE_STR_COUNT); return lines * 16; }, }); // Mock getComputedStyle const originGetComputedStyle = window.getComputedStyle; window.getComputedStyle = (ele) => { const style = originGetComputedStyle(ele); style.lineHeight = '16px'; return style; }; afterAll(() => { Object.defineProperty(HTMLElement.prototype, 'offsetHeight', { get: originOffsetHeight, }); window.getComputedStyle = originGetComputedStyle; }); it('🎏 filter test', async () => { const fn = jest.fn(); const html = mount( , ); await waitForComponentToPaint(html, 200); act(() => { html .find('.ant-table-cell label.ant-checkbox-wrapper input') .at(1) .simulate('change', { target: { checked: true, }, }); }); await waitForComponentToPaint(html, 200); expect(fn).toBeCalledTimes(1); }); });