如何使用jest框架测试void javascript函数(一个不返回任何东西的函数)?你能举一个例子吗?
/**
* this function is used to toggle the input type password field
* @param element {DOMElement} - field to be toggled
*/
export const togglePassword = (element) => {
const type = element.getAttribute('type');
if (type === 'text') {
element.setAttribute('type', 'password');
} else {
element.setAttribute('type', 'text');
}
}
Run Code Online (Sandbox Code Playgroud)
我们如何测试这种类型的功能?