diff --git a/packages/lucide-react-native/__mocks__/react-native-svg/index.ts b/packages/lucide-react-native/__mocks__/react-native-svg/index.ts index 8ebb9b6dc..b61dec342 100644 --- a/packages/lucide-react-native/__mocks__/react-native-svg/index.ts +++ b/packages/lucide-react-native/__mocks__/react-native-svg/index.ts @@ -4,8 +4,9 @@ import type { LucideProps } from '../../src/createReactComponent'; export type { SvgProps } from 'react-native-svg'; const createComponent = function (name: string) { - const component = (props: LucideProps) => { - return React.createElement(name, props, props.children); + // React Native identifies elements by `testID`, the DOM equivalent is `data-testid` + const component = ({ testID, ...props }: LucideProps) => { + return React.createElement(name, { ...props, 'data-testid': testID }, props.children); }; component.displayName = name; diff --git a/packages/lucide-react-native/src/Icon.ts b/packages/lucide-react-native/src/Icon.ts index f2346235e..184a8e48e 100644 --- a/packages/lucide-react-native/src/Icon.ts +++ b/packages/lucide-react-native/src/Icon.ts @@ -107,7 +107,7 @@ const Icon = forwardRef( { ref, ...toNativeSvgAttributes(svgAttributes), - 'data-testid': testID, + testID, ...rest, }, [ diff --git a/packages/lucide-react-native/tests/Icon.spec.tsx b/packages/lucide-react-native/tests/Icon.spec.tsx index 5c55e0b1c..09d044cd7 100644 --- a/packages/lucide-react-native/tests/Icon.spec.tsx +++ b/packages/lucide-react-native/tests/Icon.spec.tsx @@ -47,6 +47,17 @@ describe('Using Icon Component', () => { expect(container.firstChild).toBeDefined(); }); + it('should pass the testID to the rendered element', async () => { + const { container, getByTestId } = render( + , + ); + + expect(getByTestId('air-vent-icon')).toBe(container.firstChild); + }); + it('should support nonScalingStroke', async () => { const { container } = render(