小编Cha*_*iss的帖子

我如何使用 jest 来测试带有 DOM 元素的 javascript 代码

我对 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

5
推荐指数
1
解决办法
7154
查看次数

标签 统计

jestjs ×1