Skip to content

Commit

Permalink
fix(table): children of column should be kept in sync (#364)
Browse files Browse the repository at this point in the history
  • Loading branch information
unix committed Aug 14, 2020
1 parent a43de94 commit b58d96b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 18 additions & 0 deletions components/table/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,22 @@ describe('Table', () => {
expect(wrapper.find('thead').find('tr').at(0).text()).toBe('test2')
expect(() => wrapper.unmount()).not.toThrow()
})

it('the changes of children should be tracked', () => {
const Mock = ({ label }: { label: string }) => {
return (
<Table data={data}>
<Table.Column prop="description">{label}</Table.Column>
</Table>
)
}
const wrapper = mount(<Mock label="test1" />)
expect(wrapper.find('thead').find('tr').at(0).text()).toBe('test1')

act(() => {
wrapper.setProps({ label: 'test2' })
})
expect(wrapper.find('thead').find('tr').at(0).text()).toBe('test2')
expect(() => wrapper.unmount()).not.toThrow()
})
})
2 changes: 1 addition & 1 deletion components/table/table-column.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const TableColumn: React.FC<React.PropsWithChildren<TableColumnProps>> = ({
value: `${prop}`.trim(),
width,
})
}, [label, prop, width])
}, [children, label, prop, width])

return null
}
Expand Down

0 comments on commit b58d96b

Please sign in to comment.