我需要一种方法来确定 Jest 中 HTML 元素的类型。我尝试了下面的代码来查看 HTMLLabelElement 是否可用。我收到 ReferenceError:HTMLLabelElement 未定义
it('check HTML label Element type', async () => {
const doc = document.createElement('label');
console.log(doc instanceof HTMLLabelElement);
});
如果有人对此有任何想法,请告诉我。
我认为你只是有一个语法错误。我复制了你的代码片段并重新编写了它,它在这里工作了。
function it(a,b) {
foo();
}
async function foo() {
const doc = document.createElement('label');
console.log(doc instanceof HTMLLabelElement);
}
it('check HTML label Element type',foo);
if (true) {
const doc = document.createElement('label');
console.log(doc instanceof HTMLLabelElement);
foo();
}