我找到了一个将文本转换为 HTML 的 JavaScript 函数。这是功能
export default function ToText(node) {
let tag = document.createElement("div");
tag.innerHTML = node;
node = tag.innerText;
return node;
}
我试图测试该功能,但它无法正常工作。这是我的测试脚本
import ToText from '../ToText';
it('check whether ToText function is working or not', () => {
const a = "<P>This is a mock test for this function.</P>";
const b = `This is a mock test for this function`;
expect(ToText(a)).toBe(b);
});
不工作的原因可能是什么,请帮忙?