reactjs - 开玩笑地获取元素的子元素
问题描述
<div
class="btnWrap"
data-testid="footer-button"
>
<button
class="Polaris-Button Polaris-Button--primary"
type="button"
>
<span
class="Polaris-Button__Content"
>
<span
class="Polaris-Button__Text"
>
Button
</span>
</span>
</button>
</div>
我有这个组件并测试它我已经完成
test("Test footer button disable false", () => {
args.disabled = false;
const { debug, getByTestId } = render(
<AppProvider>
<Footer {...args} />
</AppProvider>
);
const element = getByTestId("footer-button");
console.log(getByTestId("footer-button").closest("button"));
expect(element.getAttribute("disabled")).toBe(null);
debug();
});
我想检查该按钮是否被禁用以获取我使用过的按钮
console.log(getByTestId("footer-button").closest("button"));
但是这个的输出是空的。我怎样才能做到这一点?
在我的主要代码中,我无法将 testid 提供给按钮组件。
解决方案
推荐阅读
- r - 是否有在 R 中定义时间变量的函数?
- java - Stream takeWhile 用于同一管道中的排序流
- javascript - 如果使用 javascript 在 iFrame 中打开页面,则重定向
- python - 在网络上实现多个 RaspPi 之间完全通信的最佳方式是什么?
- python - 获取所有隐藏的href链接selenium python
- python-3.x - 如何使用 VIPS 进行图像标准化?
- python - seq2seq 预测下一个时间步
- c# - 如何在 C# core 2.2 中导入标准 ps 模块?
- android - 有没有办法查看 FrameLayout 中有哪些片段?
- python - np.where 对 np.nan 的处理(NaN 评估为值 < 0)