mardi 27 novembre 2018

Testing DOM in Jest

Im new to Testing , Im stuck here need some help I have JS like

const images = document.querySelectorAll("article img");
if (images.length > 0) {
  images.forEach(img => {
    img.addEventListener("click", function(e) {
      window.open(e.target.src, "__blank");
    });
  });
}

and Im trying to write test case for this code using jest and I have written something like

describe("open image in new Tab", () => {
    beforeEach(() => {
    const images = document.createElement("div");
    images.innerHTML = `
      <div>
        <article>
          <img></img>
        </article>
      </div>
    `;
  });
})

and i m confuse how to go further, any kind of tutorial or link will be helpful.

Aucun commentaire:

Enregistrer un commentaire