title: How can I run a unit test in a browser environment?
body: <p>I am writing a test for some code that manipulates the DOM, and I wanted to run it in a browser environment and I don't know how.</p>
  
  <p>I wrote a mockup test using the testing library <a href="https://github.com/avajs/ava" rel="nofollow noreferrer">AVA</a>, for my small library <a href="https://github.com/marcofugaro/promisify-dom-selector" rel="nofollow noreferrer">promisify-dom-selector</a>:</p>
  
  <pre><code>const test = require('ava')
  const promisifyDOMSelector = require('index.js')
  
  test('pGetElementById works', t =&gt; {
    const pGetElementById = promisifyDOMSelector(document.getElementById)
  
    pGetElementById('load-later')
      .then((el) =&gt; {
        t.deepEqual(el, document.getElementById('load-later'))
      })
  
    const testEl = document.createElement('div')
    testEl.id = 'load-later'
    document.body.appendChild(testEl)
  })
  </code></pre>
  
  <p>and wanted to run it in <a href="https://developers.google.com/web/updates/2017/06/headless-karma-mocha-chai" rel="nofollow noreferrer">Headless Chrome</a>.</p>
  
  <p>I've tried setting up Karma with the ava plugin <a href="https://github.com/avajs/karma-ava" rel="nofollow noreferrer">karma-ava</a> but it doesn't even work, here is the error message:</p>
  
  <p><a href="https://i.stack.imgur.com/QAVmg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QAVmg.png" alt=""></a></p>
  
  <p>I wouldn't go with the Karma route if possible, but I don't know of any other way! What can I do?</p>