Aye*_*ghe 27 unit-testing jestjs react-testing-library
在 React 测试库中,我们有两个函数,称为toBeInTheDocument()和toBeVisible()。
1 expect(screen.getByText('hello')).toBeInTheDocument();
2 expect(screen.getByText('hello')).toBeVisible();
Run Code Online (Sandbox Code Playgroud)
看来这两个断言的行为是相同的。它们有什么区别,各自的用例是什么?
Jon*_*ern 39
toBeInTheDocument只是查找 DOM 树中的元素,无论可见性如何
toBeVisible检查多个属性以查看其是否可见,例如
display不等于noneopacity比...更棒0hidden属性不存在visibility不等于hidden或collapse| 归档时间: |
|
| 查看次数: |
26240 次 |
| 最近记录: |