Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Icon): fix override of data-testid property when provided #1637

Merged
merged 1 commit into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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