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?