我对 javascript 很陌生,我一直在尝试为他的代码编写测试,但我无法做到,我们应该使用玩笑。我研究了很久没有找到解决方案。
document.getElementById("signup").addEventListener("submit", function(e) {
e.preventDefault();
data = {
username: document.getElementById("username").value,
email: document.getElementById("email").value,
password: document.getElementById("password").value,
confirm_password: document.getElementById("confirmPassword").value,
};
});
signUp = (data) => {
fetch("https://diaryapi-v2.herokuapp.com/mydiary/v1/auth/register", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(data)
})
.then(res => res.json())
.then(data => {
if (data.message === "Your account was created") {
let msg = data.message;
document.getElementById("white").innerHTML = msg;
window.location.href = "/signin";
} else {
let msg = Object.values(data);
console.log(msg)
document.getElementById("white").innerHTML = msg;
}
})
.catch(error => console.error("Error:", error));
}Run Code Online (Sandbox Code Playgroud)
jestjs ×1