Skip to content

Commit

Permalink
fix(Icon): fix override of data-testid property when provided (#1637)
Browse files Browse the repository at this point in the history
  • Loading branch information
langz authored Oct 14, 2022
1 parent a9bbce4 commit d335a14
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/dnb-eufemia/src/components/icon/Icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ export const prepareIcon = (props, context) => {
}
if (wrapperParams['aria-hidden']) {
if (
!wrapperParams['data-testid'] &&
typeof process !== 'undefined' &&
process.env.NODE_ENV === 'test'
) {
Expand Down
22 changes: 22 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,28 @@ describe('Icon component', () => {
).toBe(false)
})

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

it('should set data-testid when provided', () => {
const Comp = mount(
<Component
icon={question}
aria-label="question icon"
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 d335a14

Please sign in to comment.