Skip to content

Commit

Permalink
fix(Icon): fix override of data-testid property when provided
Browse files Browse the repository at this point in the history
  • Loading branch information
langz committed Oct 13, 2022
1 parent 1a90c72 commit d623e75
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/dnb-eufemia/src/components/icon/Icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,13 @@ export const prepareIcon = (props, context) => {
title, // to show on hover, if defined
...attributes,
})

if (!alt && typeof wrapperParams['aria-hidden'] === 'undefined') {
wrapperParams['aria-hidden'] = true
}
if (wrapperParams['aria-hidden']) {
if (
!wrapperParams['data-testid'] &&
typeof process !== 'undefined' &&
process.env.NODE_ENV === 'test'
) {
Expand Down
16 changes: 16 additions & 0 deletions packages/dnb-eufemia/src/components/icon/__tests__/Icon.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,22 @@ describe('Icon component', () => {
).toBe(false)
})

it('should set a data-testid property', () => {
const Comp = mount(<Component icon={question} />)
expect(
Comp.find('span.dnb-icon').instance().getAttribute('data-testid')
).toBe('SvgComponent icon')
})

it('should set the data-testid provided', () => {
const Comp = mount(
<Component icon={question} data-testid="custom-data-testid-value" />
)
expect(
Comp.find('span.dnb-icon').instance().getAttribute('data-testid')
).toBe('custom-data-testid-value')
})

it('should validate with ARIA rules', async () => {
const Comp = mount(<Component {...props} />)
expect(await axeComponent(Comp)).toHaveNoViolations()
Expand Down

0 comments on commit d623e75

Please sign in to comment.