我有如下文件。
<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
<p id="para">My first paragraph.</p>
</body>
</html>
我正在我的React App中使用以下代码
const fieldElement = document.getElementById(fieldError);
现在如何在我的React测试用例场景中测试此特定行
it("should provide fieldElement for the id", async () => {
let fieldError = "para"
// Need to write test for document.getElemetById here
});
有人可以对此提供一些启示。
[使用.createRef()
获取对DOM元素的引用:https://reactjs.org/docs/refs-and-the-dom.html