Skip to content

fix onChange error when total is string #357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/Pagination.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ import LOCALE from './locale/zh_CN';

function noop() {}

function isInteger(value) {
function isInteger(v) {
const value = Number(v);
return (
// eslint-disable-next-line no-restricted-globals
typeof value === 'number' && isFinite(value) && Math.floor(value) === value
typeof value === 'number' &&
!isNaN(value) &&
isFinite(value) &&
Math.floor(value) === value
);
}

Expand Down
23 changes: 23 additions & 0 deletions tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,3 +416,26 @@ describe('current value on onShowSizeChange when total is 0', () => {
expect(wrapper4.exists('.rc-pagination-options-size-changer')).toBe(true);
});
});

describe('should emit onChange when total is string', () => {
let wrapper;
const onChange = jest.fn();

beforeEach(() => {
wrapper = mount(
<Pagination total="100" pageSize={10} onChange={onChange} />,
);
});

afterEach(() => {
wrapper.unmount();
onChange.mockReset();
});

it('onChange should be called when click page', () => {
const pagers = wrapper.find('.rc-pagination-item-3');
const page1 = pagers.at(0);
page1.simulate('click');
expect(onChange).toBeCalledWith(3, 10);
});
});