gpt4 book ai didi

reactjs - 如何使用 react-native-testing-library getByRole

转载 作者:行者123 更新时间:2023-12-05 04:58:31 34 4
gpt4 key购买 nike

我正在尝试在 React Native 测试库中使用 getByRole 但我终究无法弄清楚语法

有问题的组件-

<Text 
accessibilityRole={'button'}
accessibilityLabel={'upvote count'}
style={[styles.upvoteText, styles.upvoteCount]}>
{upvoteCount}
</Text>

和我的代码

expect(getByRole('button', {name: 'upvote count'} as MatcherOptions)).toBe(2)

最佳答案

所以,我正在研究类似的东西。我在 the docs 中看到了这个帮助解决这个问题:

在组件中

<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();
});

关于reactjs - 如何使用 react-native-testing-library getByRole,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63907058/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com