kei*_*eil 6 typescript reactjs jestjs react-native react-testing-library
我正在尝试在 React Native 测试库中使用getByRole,但我一生都无法弄清楚语法
有问题的组件 -
<Text
accessibilityRole={'button'}
accessibilityLabel={'upvote count'}
style={[styles.upvoteText, styles.upvoteCount]}>
{upvoteCount}
</Text>
Run Code Online (Sandbox Code Playgroud)
和我的代码
expect(getByRole('button', {name: 'upvote count'} as MatcherOptions)).toBe(2)
Run Code Online (Sandbox Code Playgroud)
所以,我正在做类似的事情。我在文档中看到了这个来帮助解决这个问题:
<Text
accessibilityRole={'button'}
accessibilityLabel={'upvote count'}
style={[styles.upvoteText, styles.upvoteCount]}>
{upvoteCount}
</Text>
Run Code Online (Sandbox Code Playgroud)
it('gets the button', () => {
const { getByA11yRole, getByA11yLabel } = render(<Text>foo</Text>);
expect(getByA11yRole('button')).toBeDefined();
expect(getbyA11yRole('upvote count')).toBeDefined();
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3592 次 |
| 最近记录: |