title: How to test addEventListener in Mocha/Chai/Sinon with vanillajs and nodejs?
body: <p>I have an issue with Mocha testing an eventlistener that checks for input.
  My environment is with plain javascript, nodejs and mocha/chai/sinon for testing.
  I wrote some other tests that are working, basically checking functions but the test hits on "Cannot read property 'addEventListener' of null".</p>
  
  <p>Since I'm quite new to testing I've dug around in the documentation, added JSDOM and such but no luck. I simply don't know how to check for the eventlistener. Many of the threads already available are React environments which seem to have some sort of built in applications that helps them, but not me.</p>
  
  <p>So it's basically this, really narrowed down:</p>
  
  <pre><code>const userInput = document.querySelector("#userInfo");
  userInput.addEventListener("input", changeContent);
  </code></pre>
  
  <p>It checks for user input and in the changeContent method it just checks for length etc.
  Any takers on how I should do this?</p>
  
  <p><strong>Edit:</strong>
  Slight workaround that "skips" my issue, but it would be nice to learn how to solve it in a test anyway. With this the test passes (because it ignores it).</p>
  
  <p>Workaround, since the test points eventListener to null:</p>
  
  <pre><code>if(userInput){
    userInput.addEventListener("input", changeContent)
  }
  </code></pre>