AntD unit testing table render

Viewed 762

How to unit test AntD Table render column?

Here's my code

const columns = [
  {
    title: 'Evaluation Form',
    dataIndex: 'projectName',
    key: 'projectName',
    render: (text, record) => `${!_.isNil(text) ? text : '---'} - ${record.employeeName}`,
  },
]

<Table
  columns={columns}
/>

Here's the result from the test enter image description here

1 Answers

The return value of render should be a React node or an object with a children prop which could be a string or React node. Change the render function to this:

const columns = [
  {
    title: 'Evaluation Form',
    dataIndex: 'projectName',
    key: 'projectName',
    render: (text, record) => ({
       children: `${!_.isNil(text) ? text : '---'} - ${record.employeeName}`,
       ...
    })
  },
]
Related