Skip to content

Commit

Permalink
chore: Add shouldCellUpdate test case
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Jul 29, 2020
1 parent 7525894 commit 659158f
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/Cell.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React from 'react';
import { mount } from 'enzyme';
import Table from '../src';

describe('Table.Cell', () => {
it('shouldCellUpdate', () => {
let renderTime = 0;

const Demo = () => {
const [, forceUpdate] = React.useState({});

return (
<>
<Table
data={[{ key: 'light' }]}
columns={[
{
shouldCellUpdate: (record, prevRecord) => prevRecord.key !== record.key,
dataIndex: 'key',
render: value => {
renderTime += 1;
return value;
},
},
]}
/>
<button
type="button"
onClick={() => {
forceUpdate({});
}}
/>
</>
);
};

const wrapper = mount(<Demo />);

for (let i = 0; i < 100; i += 1) {
wrapper.find('button').simulate('click');
expect(renderTime).toEqual(1);
}
});
});

1 comment on commit 659158f

@vercel
Copy link

@vercel vercel bot commented on 659158f Jul 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.