I'm trying to test a table being built using react testing library
I'm using debug which outputs
<body>
<div>
<div
class="table-wrapper"
>
<div
class="table-component__header"
/>
<table
class="test-table"
>
<tbody>
<tr>
<td
class="text-grid-item"
data-testid="text-grid-item"
>
test table data
</td>
</tr>
</tbody>
<tfoot
class="table_footer"
>
<tr>
<td />
</tr>
</tfoot>
</table>
</div>
</div>
</body>
I'm trying to assert test table data is there with
expect(findByTestId('text-grid-item')).toHaveTextContent('test table dat')
but it fails with
received value must be a Node.
Received has type: object
Received has value: {}
How can I assert the text test table data is there
import React from 'react'
import { render } from '@testing-library/react'
import { Table } from './table'
const givenTableWithElement = (test: Array<TableElement>) => {
const table = {
tableEntries: [{ tableElements: test }],
type: 'table',
tableType: 'test'
}
return table
}
describe('Components should render depending on their prop type', () => {
test('Given table element is text, when rendered, text table class should be returned', () => {
const imageTableTest: TableProps = givenTableWithElement([
{
text: 'test table data',
display: {
mobile: true,
wrap: false
}
}
])
const { debug } = render(<Table {...imageTableTest} />)
debug()
const { getByTestId } = render(<Table {...imageTableTest} />)
expect(findByTestId('text-grid-item')).toHaveTextContent('test table dat')
})
})