Skip to content
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
1 change: 1 addition & 0 deletions src/Body/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ function Body<RecordType>({
}, [
data,
prefixCls,
onRow,
measureColumnWidth,
stickyOffsets,
expandedKeys,
Expand Down
47 changes: 39 additions & 8 deletions tests/Table.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,16 +458,47 @@ describe('Table.Basic', () => {
expect(wrapper.find('tbody tr').length).toBeTruthy();
});

it('renders onRow correctly', () => {
const onRow = (record, index) => ({
id: `row-${record.key}`,
index,
describe('onRow', () => {
it('renders onRow correctly', () => {
const onRow = (record, index) => ({
id: `row-${record.key}`,
index,
});
const wrapper = mount(createTable({ onRow }));

expect(wrapper.find('tbody tr').length).toBeTruthy();
wrapper.find('tbody tr').forEach((tr, index) => {
expect(tr.props().id).toEqual(`row-${data[index].key}`);
});
});
const wrapper = mount(createTable({ onRow }));

expect(wrapper.find('tbody tr').length).toBeTruthy();
wrapper.find('tbody tr').forEach((tr, index) => {
expect(tr.props().id).toEqual(`row-${data[index].key}`);
it('onRow should keep update', () => {
const Test = () => {
const [count, setCount] = React.useState(0);

return (
<div>
<Table
columns={[{ dataIndex: 'key' }]}
data={[{ key: 0 }]}
onRow={() => ({
onClick() {
setCount(count + 1);
},
})}
/>
<span id="count">{count}</span>
</div>
);
};
const wrapper = mount(<Test />);
for (let i = 0; i < 10; i += 1) {
wrapper
.find('tbody tr td')
.last()
.simulate('click');
expect(wrapper.find('#count').text()).toEqual(String(i + 1));
}
});
});

Expand Down