Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

501
Visualizações
JEST how do you test event.preventDefault and event listeners in vanilla JS?

I'm rather new to JS but attentive to documentation and not lazy to read through all the stuff, so I've read Jest documentation and watched quite a few tutorials. I understand them, but then I absolutely don't understand how to approach this:

document.getElementsByTagName('form')[0].addEventListener('submit', function (event) {
    event.preventDefault();
    
    userName = document.getElementById('usrname').value
    sessionStorage.setItem('userName', document.getElementById('usrname').value);
    
    window.location.assign('game.html');
<form>
                <label for="usrname">Enter name:</label>
                <input type="text" id="usrname" name="username" maxlength="23" required>
                <input id="sbmt" type="submit" value="Play">
</form>

It is a simple game written for a school task and It was said to test it with jest to improve the project. We haven't studied any of it and no assistance is given cos it's extra and we're supposed to figure it out ourselves. I am really desperate. After so much time spent I would really like to understand. Could anyone at least guide me toward the answer? It seems like a lot of code with loads of mock functions. And, spoiler alert - idiotic existential question, if I mock everything how does it test my function and what's the point? At which point do I call it and how do I address it in this case, what do I export?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda