Javascript Jest/JSDOM—分配给文档时测试窗口中红色输出的页面
这是我的测试。当比较函数失败时,我将向输入框添加一个类,因此我的测试预期类列表的长度为2Javascript Jest/JSDOM—分配给文档时测试窗口中红色输出的页面,javascript,unit-testing,jestjs,jsdom,Javascript,Unit Testing,Jestjs,Jsdom,这是我的测试。当比较函数失败时,我将向输入框添加一个类,因此我的测试预期类列表的长度为2 describe('confirm password element', () => { it('adds a class to the input box when the text fails comparison check', () => { document.body.innerHTML = ' <form>' +
describe('confirm password element', () => {
it('adds a class to the input box when the text fails comparison check', () => {
document.body.innerHTML =
' <form>' +
'<input class="confirm-password">' +
' </form>';
const e = document.querySelector('.confirm-password').classList;
// keypress event to trigger comparison function will be here.
expect(e).toHaveLength(2);
})
})
当我注释掉以“const e”开头的最后第二行时,这将停止文本输出。顺便说一句,尽管有这些不必要的输出,测试还是正确地进行了评估 您是否使用
--verbose
运行测试?该代码段看起来不像是错误。它可能只是非常健谈的日志记录
ect]}, Symbol(wrapper): {Symbol(impl): [Circular]}, Symbol(location info): {"end": 32, "endTag": [Object], "start": 19, "startTag": [Object]}}, "previousSibling": null}, Symbol(wrapper): {Symbol(impl): [Circular]}, Symbol(location info): undefined}}, Symbol(wrapper): {Symbol(impl): [Circular]}, Symbol(location info): undefined}, "previousSibling": null}, Symbol(wrapper): {Symbol(impl): [Circular]}, Symbol(location info): undefined}, "tokens": ["confirm-password"]}}