-
Notifications
You must be signed in to change notification settings - Fork 274
feat: add getAllByTestId and queryAllByTestId queries #198
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
feat: add getAllByTestId and queryAllByTestId queries #198
Conversation
- Filter out intermediate components in getAllByTestId. testIDs may be passed down to child components and appearing multiple times in the render tree. Some React Native components render multiple anyways. <Text> is an example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Can you also update the TypeScript types and tests?
Just noticed flow is yelling at me. Ya I'll look at the TS types. Forgot about them... |
You have any suggestions for fixing the flow error? I'm not very familiar with flow. Seems like it doesn't know that |
You'll need too add a type annotation to filter that it returns a single ReactTestInstance, something like |
That is a very unhelpful error telling you to specify a return type. I tried something like that and it wasn't happy... |
Would be nice to also update this file 😅 https://github.com/callstack/react-native-testing-library/blob/master/typings/__tests__/index.test.tsx |
Didn't realize what that was doing... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a smoke test to make sure TS works :)
Thank you so much! |
Any chance you could create a release for this? I could pin it to a master commit for a while but I'd rather be done with it. But I realize you probably don't want a new release for every little thing. Do what you need to. |
We'll publish it tomorrow :) |
Released 1.10 |
Summary
Implements
getAllByTestId
andqueryAllByTestId
queries.Closes #186, Resolves #161
Test plan
I wrote a test and added two
<Text>
components to the component under test as a simple, contrived example. If you want me to think of a more realistic use case or you want to suggest one I'd be happy to try that. Maybe buttons in a loop or a child component or something. But I don't want to add complexity to the example component.