Skip to content

Commit 60c9e19

Browse files
cwjTerracemachixian
andauthored
fix onChange error when total is string (#357)
* fix: isInteger * new test case Co-authored-by: machixian <[email protected]>
1 parent b5fe328 commit 60c9e19

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/Pagination.jsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ import LOCALE from './locale/zh_CN';
88

99
function noop() {}
1010

11-
function isInteger(value) {
11+
function isInteger(v) {
12+
const value = Number(v);
1213
return (
1314
// eslint-disable-next-line no-restricted-globals
14-
typeof value === 'number' && isFinite(value) && Math.floor(value) === value
15+
typeof value === 'number' &&
16+
!isNaN(value) &&
17+
isFinite(value) &&
18+
Math.floor(value) === value
1519
);
1620
}
1721

tests/index.test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,3 +416,26 @@ describe('current value on onShowSizeChange when total is 0', () => {
416416
expect(wrapper4.exists('.rc-pagination-options-size-changer')).toBe(true);
417417
});
418418
});
419+
420+
describe('should emit onChange when total is string', () => {
421+
let wrapper;
422+
const onChange = jest.fn();
423+
424+
beforeEach(() => {
425+
wrapper = mount(
426+
<Pagination total="100" pageSize={10} onChange={onChange} />,
427+
);
428+
});
429+
430+
afterEach(() => {
431+
wrapper.unmount();
432+
onChange.mockReset();
433+
});
434+
435+
it('onChange should be called when click page', () => {
436+
const pagers = wrapper.find('.rc-pagination-item-3');
437+
const page1 = pagers.at(0);
438+
page1.simulate('click');
439+
expect(onChange).toBeCalledWith(3, 10);
440+
});
441+
});

0 commit comments

Comments
 (0)