Reputation: 433
I'm trying to use getByRole
in react native testing library but can't for the life of me figure out the syntax
Component in question-
<Text
accessibilityRole={'button'}
accessibilityLabel={'upvote count'}
style={[styles.upvoteText, styles.upvoteCount]}>
{upvoteCount}
</Text>
and my code
expect(getByRole('button', {name: 'upvote count'} as MatcherOptions)).toBe(2)
Upvotes: 6
Views: 4581
Reputation: 115
So, I'm working on something similar. I saw this in the docs to help with this case:
<Text
accessibilityRole={'button'}
accessibilityLabel={'upvote count'}
style={[styles.upvoteText, styles.upvoteCount]}>
{upvoteCount}
</Text>
it('gets the button', () => {
const { getByA11yRole, getByA11yLabel } = render(<Text>foo</Text>);
expect(getByA11yRole('button')).toBeDefined();
expect(getbyA11yRole('upvote count')).toBeDefined();
});
Upvotes: 1