Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

100
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda