diff --git a/tests/data-aria.test.tsx b/tests/data-aria.test.tsx index dbf1523c..90b2b78a 100644 --- a/tests/data-aria.test.tsx +++ b/tests/data-aria.test.tsx @@ -1,9 +1,10 @@ import React from 'react'; +import type { RenderResult } from '@testing-library/react'; import { render } from '@testing-library/react'; import Pagination from '../src'; describe('data and aria props', () => { - let wrapper; + let wrapper: RenderResult; describe('with simple prop', () => { beforeEach(() => { diff --git a/tests/index.test.tsx b/tests/index.test.tsx index 16f0480e..a08ed026 100644 --- a/tests/index.test.tsx +++ b/tests/index.test.tsx @@ -1,3 +1,4 @@ +import type { RenderResult } from '@testing-library/react'; import { render, fireEvent } from '@testing-library/react'; import Select from 'rc-select'; import React from 'react'; @@ -5,9 +6,9 @@ import Pagination from '../src'; import { resetWarned } from 'rc-util/lib/warning'; describe('Default Pagination', () => { - let wrapper; + let wrapper: RenderResult; const onChange = jest.fn(); - const $$ = (selector) => wrapper.container.querySelectorAll(selector); + const $$ = (selector: string) => wrapper.container.querySelectorAll(selector); beforeEach(() => { wrapper = render(); @@ -26,9 +27,9 @@ describe('Default Pagination', () => { }); describe('Uncontrolled Pagination', () => { - let wrapper; + let wrapper: RenderResult; const onChange = jest.fn(); - const $$ = (selector) => wrapper.container.querySelectorAll(selector); + const $$ = (selector: string) => wrapper.container.querySelectorAll(selector); function shouldHighlightRight(current = 1) { const pagers = $$('li:not(.rc-pagination-total-text)'); @@ -205,7 +206,7 @@ describe('Uncontrolled Pagination', () => { }); describe('Controlled Pagination', () => { - let wrapper; + let wrapper: RenderResult; const onChange = jest.fn(); beforeEach(() => { @@ -344,7 +345,7 @@ describe('Other props', () => { // https://github.com/ant-design/ant-design/issues/10524 describe('current value on onShowSizeChange when total is 0', () => { - let wrapper; + let wrapper: RenderResult; const onShowSizeChange = jest.fn(); const onChange = jest.fn(); @@ -485,7 +486,7 @@ describe('current value on onShowSizeChange when total is 0', () => { }); describe('should emit onChange when total is string', () => { - let wrapper; + let wrapper: RenderResult; const onChange = jest.fn(); beforeEach(() => { @@ -508,10 +509,9 @@ describe('should emit onChange when total is string', () => { }); describe('keyboard support', () => { - let wrapper; + let wrapper: RenderResult; const onChange = jest.fn(); - const $$ = (selector) => wrapper.container.querySelectorAll(selector); - const $ = (selector) => wrapper.container.querySelector(selector); + const $ = (selector: string) => wrapper.container.querySelector(selector); beforeEach(() => { wrapper = render( @@ -572,12 +572,12 @@ describe('keyboard support', () => { }); describe('select in sequence', () => { - const serializeCls = (items) => - Array.from(items).map((item: HTMLElement) => + const serializeCls = (items: NodeListOf) => + Array.from(items).map((item) => item.getAttribute('class').replaceAll('rc-pagination-', ''), ); - function sequenceSelector(total) { + function sequenceSelector(total: number) { describe(`should sequence select ${total} pages`, () => { const { container } = render(); const cls = serializeCls(container.querySelectorAll('li')); @@ -586,11 +586,11 @@ describe('select in sequence', () => { const pages = Math.floor((total - 1) / 10) + 1; for (let i = 2; i <= pages; i++) { it(`should select page ${i}`, () => { - const { container } = render( + const { container: pageContainer } = render( , ); - const cls = serializeCls(container.querySelectorAll('li')); - expect(cls).toMatchSnapshot(); + const clsString = serializeCls(pageContainer.querySelectorAll('li')); + expect(clsString).toMatchSnapshot(); }); } }); diff --git a/tests/itemRender.test.tsx b/tests/itemRender.test.tsx index 3de3b447..50c426f2 100644 --- a/tests/itemRender.test.tsx +++ b/tests/itemRender.test.tsx @@ -1,12 +1,13 @@ import React from 'react'; +import type { RenderResult } from '@testing-library/react'; import { render } from '@testing-library/react'; import Pagination from '../src'; describe('itemRender', () => { - let wrapper; + let wrapper: RenderResult; const currentPage = 12; - const itemRender = (current) => {current}; - const $$ = (selector) => wrapper.container.querySelector(selector); + const itemRender = (current: number) => {current}; + const $$ = (selector: string) => wrapper.container.querySelector(selector); beforeEach(() => { wrapper = render( @@ -47,7 +48,7 @@ describe('itemRender', () => { { + itemRender={(_, type, originalElement) => { if (type === 'page') { return null; } @@ -63,7 +64,7 @@ describe('itemRender', () => { { + itemRender={(_, type, originalElement) => { if (type === 'prev' || type === 'next') { return null; } diff --git a/tests/jumper.test.tsx b/tests/jumper.test.tsx index 63906325..39f0f5fe 100644 --- a/tests/jumper.test.tsx +++ b/tests/jumper.test.tsx @@ -1,11 +1,12 @@ +import type { RenderResult } from '@testing-library/react'; import { render, fireEvent } from '@testing-library/react'; import Pagination from '../src'; import * as React from 'react'; describe('Pagination with jumper', () => { - let wrapper; + let wrapper: RenderResult; const onChange = jest.fn(); - const $$ = (selector) => wrapper.container.querySelector(selector); + const $$ = (selector: string) => wrapper.container.querySelector(selector); beforeEach(() => { wrapper = render( @@ -68,10 +69,10 @@ describe('Pagination with jumper', () => { }); it('should not jump when input empty string', () => { - const onChange = jest.fn(); + const onChangeFn = jest.fn(); const { container } = render( { expect( container.querySelector('.rc-pagination-item-active'), ).toHaveTextContent('3'); - expect(onChange).toHaveBeenLastCalledWith(3, 10); + expect(onChangeFn).toHaveBeenLastCalledWith(3, 10); }); }); describe('simple quick jumper', () => { - let wrapper; + let wrapper: RenderResult; const onChange = jest.fn(); beforeEach(() => { diff --git a/tests/options.test.tsx b/tests/options.test.tsx index 156230ce..715bb959 100644 --- a/tests/options.test.tsx +++ b/tests/options.test.tsx @@ -4,19 +4,17 @@ import zhCN from '../src/locale/zh_CN'; import Options from '../src/Options'; import * as React from 'react'; -const WrapperOptions = (props) => { - return ( - - ); -}; +const WrapperOptions: React.FC = (props) => ( + +); describe('Options', () => { it('should render correctly', () => { diff --git a/tests/simple.test.tsx b/tests/simple.test.tsx index 476b294f..5835e353 100644 --- a/tests/simple.test.tsx +++ b/tests/simple.test.tsx @@ -1,10 +1,11 @@ +import type { RenderResult } from '@testing-library/react'; import { render, fireEvent, createEvent } from '@testing-library/react'; import Select from 'rc-select'; import React, { useState } from 'react'; import Pagination from '../src'; describe('simple Pagination', () => { - let wrapper; + let wrapper: RenderResult; beforeEach(() => { wrapper = render( @@ -48,7 +49,7 @@ describe('simple Pagination', () => { it('should return to 1 when blur goto input in control mode', () => { const App = () => { - const [current, setCurrent] = useState(1); + const [, setCurrent] = useState(1); return ; }; const { container } = render(); diff --git a/tests/sizer.test.tsx b/tests/sizer.test.tsx index a1cee0f6..b6832ccc 100644 --- a/tests/sizer.test.tsx +++ b/tests/sizer.test.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { render, fireEvent, act } from '@testing-library/react'; +import { render, fireEvent } from '@testing-library/react'; import Select from 'rc-select'; import Pagination from '../src'; diff --git a/tests/two-pagination.test.tsx b/tests/two-pagination.test.tsx index dcae5f12..8d59d382 100644 --- a/tests/two-pagination.test.tsx +++ b/tests/two-pagination.test.tsx @@ -1,10 +1,10 @@ +import type { RenderResult } from '@testing-library/react'; import { render, fireEvent } from '@testing-library/react'; import React from 'react'; import TwoPagination from './two-pagination'; describe('Two Pagination', () => { - let wrapper; - let mockPagination; + let wrapper: RenderResult; beforeEach(() => { jest.mock('../src', () => {}); diff --git a/tests/two-pagination.jsx b/tests/two-pagination.tsx similarity index 93% rename from tests/two-pagination.jsx rename to tests/two-pagination.tsx index 19094ad0..4e2e4f11 100644 --- a/tests/two-pagination.jsx +++ b/tests/two-pagination.tsx @@ -9,11 +9,11 @@ class Hello extends React.Component { }; changeSize = () => { - this.setState({ - pageSize: 50, - }); + this.setState({ pageSize: 50 }); }; + onShowSizeChange = () => {}; + render() { return ( <>