Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

491
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda