我正在使用 react-testing-libarary 来测试我的反应应用程序。出于某种原因,我需要能够通过 id
而不是 data-testid
找到元素。在文档中没有办法实现这一点。
有没有办法做到这一点?
我将渲染输出为:
const dom = render(<App />);
我正在寻找符合以下条件的东西:
const input = dom.getElemenById('firstinput');
//or
const input = dom.getById('firstinput');
原文由 aks 发布,翻译遵循 CC BY-SA 4.0 许可协议
我找到了一种方法来做到这一点。
我希望这有帮助。