meliorence / react-native-render-html

iOS/Android pure javascript react-native component that renders your HTML into 100% native views
https://meliorence.github.io/react-native-render-html/
BSD 2-Clause "Simplified" License
3.48k stars 589 forks source link

testID override issue #572

Closed DaliaElhefny closed 2 years ago

DaliaElhefny commented 2 years ago

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch react-native-render-html@6.3.4 for the project I'm working on.

I need the HTML rendered to have testID so that it can b used in automation testing My problem was that when I pass testID through defaultTextProps prop, it gets overridden with the tagName

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-render-html/src/helpers/getNativePropsForTNode.ts b/node_modules/react-native-render-html/src/helpers/getNativePropsForTNode.ts
index 113b28c..415eb92 100644
--- a/node_modules/react-native-render-html/src/helpers/getNativePropsForTNode.ts
+++ b/node_modules/react-native-render-html/src/helpers/getNativePropsForTNode.ts
@@ -70,7 +70,7 @@ export default function getNativePropsForTNode<
     children,
     onPress: syntheticOnPress,
     style: [style, passedNativeProps?.style, switchProp.style],
-    testID: tnode.tagName || undefined
+    testID: switchProp.testID ||tnode.tagName || undefined
   };
   return nativeProps as any;
 }

This issue body was partially generated by patch-package.

jsamr commented 2 years ago

@DaliaElhefny Appreciate the proposition! Are you willing to offer a PR? I'd approve it quickly.

DaliaElhefny commented 2 years ago

@jsamr Can you give me access to push the branch?

jsamr commented 2 years ago

@DaliaElhefny You don't need to, just fork this repository, create a branch with the fix, and then visit the PR page on Github, you should be able to create a PR out of your forked repository branch.

DaliaElhefny commented 2 years ago

@jsamr here is the PR https://github.com/meliorence/react-native-render-html/pull/574

DaliaElhefny commented 2 years ago

@jsamr when will be the next release?