开玩笑的测试,如果溢出隐藏的元素是否可见

发布于 2025-02-10 12:44:14 字数 840 浏览 1 评论 0原文

我有一个像滑块一样的反应组件。我想测试溢出隐藏的元素之一是否可见。

到目前为止,我拥有的是

const prevBtn = screen.getByRole('button', { name: /prev slide/i })
const juneTwentySix = await screen.findByTestId('Sun 26 Jun')
const juneThird = await screen.findByTestId('Sun 30 Jun')

expect(prevBtn).toBeDisabled()
expect(juneTwentySix).toBeVisible() <-- ok
expect(juneThird).toBeInTheDocument() <-- it's in the DOM, so it's ok to be in the document
expect(juneThird).not.toBeVisible() <-- this is where I want to check if the element is visible or not.

该滑块的建造方式: 父组件具有固定宽度:I 300px,是什么使子组件(包含日期的一个)是transform:translatex(-U {$ {Currentslide * 100}%)>

I have a react component that behaves like a slider. I wanna test if one of the elements that is hidden by the overflow is visible or not.

Slider

What I have so far is

const prevBtn = screen.getByRole('button', { name: /prev slide/i })
const juneTwentySix = await screen.findByTestId('Sun 26 Jun')
const juneThird = await screen.findByTestId('Sun 30 Jun')

expect(prevBtn).toBeDisabled()
expect(juneTwentySix).toBeVisible() <-- ok
expect(juneThird).toBeInTheDocument() <-- it's in the DOM, so it's ok to be in the document
expect(juneThird).not.toBeVisible() <-- this is where I want to check if the element is visible or not.

How is this slider built:
The parent component has a fixed width: ie 300px, and what makes the child component (the one that contains the dates) is transform: translateX(-${currentSlide * 100}%)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文