Skip to content

Commit 659158f

Browse files
committed
chore: Add shouldCellUpdate test case
1 parent 7525894 commit 659158f

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

tests/Cell.spec.tsx

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import React from 'react';
2+
import { mount } from 'enzyme';
3+
import Table from '../src';
4+
5+
describe('Table.Cell', () => {
6+
it('shouldCellUpdate', () => {
7+
let renderTime = 0;
8+
9+
const Demo = () => {
10+
const [, forceUpdate] = React.useState({});
11+
12+
return (
13+
<>
14+
<Table
15+
data={[{ key: 'light' }]}
16+
columns={[
17+
{
18+
shouldCellUpdate: (record, prevRecord) => prevRecord.key !== record.key,
19+
dataIndex: 'key',
20+
render: value => {
21+
renderTime += 1;
22+
return value;
23+
},
24+
},
25+
]}
26+
/>
27+
<button
28+
type="button"
29+
onClick={() => {
30+
forceUpdate({});
31+
}}
32+
/>
33+
</>
34+
);
35+
};
36+
37+
const wrapper = mount(<Demo />);
38+
39+
for (let i = 0; i < 100; i += 1) {
40+
wrapper.find('button').simulate('click');
41+
expect(renderTime).toEqual(1);
42+
}
43+
});
44+
});

0 commit comments

Comments
 (0)