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

99
Vistas
How to mock the DOM with support for loading ES6 modules?

I've built a Node app, and am adding unit tests. In my unit test file I need to create a mock DOM which has support for <script type='module'> tags. In other words, into my mock DOM I need to insert HTML which loads a JavaScript file JS via a <script type='module'> tag. Other than jest-dom, what options do I have to create such a mock DOM?

Of Note

  • The jsdom package does not have such support.
  • The jest-dom package has such support. But if possible, I would like to use Tape for my unit testing instead of Jest.

If there are no other options, how might I get around my issue? Would I have to refactor my code so it does not use such a tag? Or at least, refactor things so my unit tests don't depend on that tag?

Motivation Behind Question

The motivation for this is this. In my project I have an HTML file which renders a simple form to the DOM, and a separate JS module which is loaded on the same page and serves as the form handler (i.e. it makes a specific fetch request when the submit button is clicked). I originally had an integration test written using Jest (using jest-dom as the mock DOM), which does the following:

  • Renders the HTML to the test DOM.
  • Populates the form elements with test data.
  • Clicks the submit button in the test DOM.
  • Asserts that the correct fetch request is made.

There were no issues with that test. I'm now trying to refactor my automated tests away from Jest to Tape, with jsdom as the mock DOM.

Thanks.

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