Snackbar or the button inside it should be accessible through testID.
Right now when I try to test that the button inside Snackbar has been clicked I have no way to do so, Snackbar can not be retrieved using any of the react-native-testing-library query except for the byType, and even then fireEvent does not work because it tries to invoke onPress on the Snackbar itself.
PR welcome to add testID, but you should use accessibilityLabel to test your buttons which we already support.
PR welcome to add
testID, but you should useaccessibilityLabelto test your buttons which we already support.
accessibilityLabel does not work, at least not for me. Neither does text, etc. Only by type worked.
I've no idea why is it, here's a basic examples of how it fails:
Snack link
@satya164 Even the simplest test case doesn't work, link It does not work on code sandbox because it has problem with react-native, but if your tried to run the test within MySnackbar.test.tsx on your own machine, it still wouldn't work.
@anothersaddeveloper You can retrieve the button by using getByText, matching the text inside the button.
@anothersaddeveloper You can retrieve the button by using
getByText, matching the text inside the button.
You can't when you try to do it on Snackbar. I've tried it about a thousand times by now, give it a go yourself:
```
test("test plain snackbar", () => {
const { debug, getByA11yLabel, getByText } = render(
onDismiss={() => "onDismissCommentFeedback"}
action={{
label: "Undo",
accessibilityLabel: translate("general.undo"),
onPress: () => alert("Hello")
}}
theme={{ colors: { accent: "white" } }}
style={{ bottom: 62 }}
duration={Snackbar.DURATION_SHORT}
>
Hello
);
debug();
// getByA11yLabel("Undo");
// getByText("Hello");
})
```
@anothersaddeveloper Can you create a reproducible repository?