-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Cannot find custom component using selector with property value #951
Comments
Hi @andriichernenko, I'm not sure you can find your component using a string unless the component has a displayName set. So you can find using the actual component or you could use the id as it's unique. // using id only
loginView.find('[id="usernameInput"]');
// OR
// using the component (it will require FnTextInput to be imported into your test)
loginView.find(FnTextInput).find('[id="usernameInput"]'); I'm not sure why the `TextInput[id="textInput"]' works (I'm not familiar with RN) but I can only assume it has a displayName set. See this page for more info. I hope that helps! |
@samit4me Both I also tried using |
Ah that's very interesting! To replicate the issue you mentioned, I setup a small test with plain react and the suggestions I made earlier actually worked, so maybe it's a react native specific issue? I'm not sure as I've never used it. Do you have a repo or some code you can share that demonstrates the issue? |
@samit4me Note that I am using RN 0.42.3 with React 15.4.1 and Enzyme 2.8.0 due to #893 (the latest stable version is 0.44.0). |
Not sure how I didn't spot this earlier, but in the example repo and the code you posted above, the You're 💯 correct about the I also opened a PR on your repo so you can see it working if you want, I hope that resolves the issue. Thanks for sharing the code, much appreciated ✨ |
Seems like this is resolved :-) thanks everyone! |
Yeah, the tests work now, but I am afraid the issue has not been resolved (or maybe I don't quite understand how lookup is supposed to work?). Here are the lookup results I get:
<TextInput id="usernameInput" style={{...}} selectionColor="#00aa00" placeholderTextColor="#000000" autoCapitalize="none" autoCorrect={false} clearButtonMode="while-editing" />
<FnTextInput id="usernameInput" style={{...}}>
<TextInput id="usernameInput" style={{...}} selectionColor="#00aa00" placeholderTextColor="#000000" autoCapitalize="none" autoCorrect={false} clearButtonMode="while-editing">
<TextInput id="usernameInput" style={{...}} selectionColor="#00aa00" placeholderTextColor="#000000" autoCapitalize="none" autoCorrect={false} clearButtonMode="while-editing" />
</TextInput>
</FnTextInput>
<FnTextInput id="passwordInput" style={{...}}>
<TextInput id="passwordInput" style={{...}} selectionColor="#00aa00" placeholderTextColor="#000000" autoCapitalize="none" autoCorrect={false} clearButtonMode="while-editing">
<TextInput id="passwordInput" style={{...}} selectionColor="#00aa00" placeholderTextColor="#000000" autoCapitalize="none" autoCorrect={false} clearButtonMode="while-editing" />
</TextInput>
</FnTextInput>
<TextInput id="usernameInput" style={{...}} selectionColor="#00aa00" placeholderTextColor="#000000" autoCapitalize="none" autoCorrect={false} clearButtonMode="while-editing" /> |
I did a little investigation into this and it turns out the CSS selectors (e.g.
I think the keywords "render tree" can be translated to "only the native elements". This would make sense as this is the actual output. The components we write in JSX are essentially a way to compose state/props to native elements. If you remove the Does this help at all? I know I certainly learned something looking into this, thanks for sharing ✨ |
I'd recommend using |
Okay, thanks for advice! |
I have a custom text input component in my React Native app which wraps
TextInput
:I have 2 such text inputs in my login view:
I
mount()
login view in tests and try to find the text fields by their ID:Unfortunately, this lookup fails,
usernameInput
is empty.However, the following lookups work as expected:
I use react-native-mock-render to enable deep rendering, if it matters. My React Native version is 0.42.3.
The text was updated successfully, but these errors were encountered: