Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

97
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!