Skip to content

Commit

Permalink
fix(Td): fix children and add tests (#1703)
Browse files Browse the repository at this point in the history
  • Loading branch information
tujoworker authored and joakbjerk committed Mar 27, 2023
1 parent 9b5cb61 commit e120bcc
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/dnb-eufemia/src/components/table/TableTd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const Td = (
className={classnames('dnb-table__td', className)}
{...props}
>
{children}
</td>
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import React from 'react'
import { render } from '@testing-library/react'
import TableTd from '../TableTd'

describe('TableTd', () => {
it('should contain children content', () => {
render(
<table>
<tbody>
<tr>
<TableTd>td content</TableTd>
</tr>
</tbody>
</table>
)

const element = document.querySelector('td')

expect(element.textContent).toBe('td content')
})

it('should include custom attributes', () => {
render(
<table>
<tbody>
<tr>
<TableTd aria-label="custom-label">td content</TableTd>
</tr>
</tbody>
</table>
)

const element = document.querySelector('td')
const attributes = Array.from(element.attributes).map(
(attr) => attr.name
)

expect(attributes).toEqual(['role', 'class', 'aria-label'])
})

it('should have role with cell as value', () => {
render(
<table>
<tbody>
<tr>
<TableTd>td content</TableTd>
</tr>
</tbody>
</table>
)

const element = document.querySelector('td')

expect(element.getAttribute('role')).toBe('cell')
})

it('should include custom classes', () => {
render(
<table>
<tbody>
<tr>
<TableTd className="custom-class">td content</TableTd>
</tr>
</tbody>
</table>
)

const element = document.querySelector('td')
expect(Array.from(element.classList)).toEqual([
'dnb-table__td',
'custom-class',
])
})
})

0 comments on commit e120bcc

Please sign in to comment.