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

99
Views
Jest with Leaflet Markercluster

I have an issue testing something related to markerCluster. I'm using the leaflet.markercluster npm package, version 1.5.1. I'm doing something similar to an example on the git page, using the imports below:

    import * as L from 'leaflet';
    import 'leaflet.markercluster';
    import "leaflet.markercluster/dist/leaflet.markercluster";
    import "leaflet.markercluster/dist/MarkerCluster.css";
    import "leaflet.markercluster/dist/MarkerCluster.Default.css";

the variable I'm writing:

        const clusterItems = L.markerClusterGroup({
            chunkedLoading: true,
            showCoverageOnHover: false,
            iconCreateFunction: customIcon,
            removeOutsideVisibleBounds: true,
            disableClusteringAtZoom:18
        });

I'm also using react as my frontend library, with typescript if you needed to know.

Thing is, works fine when actually running the service. But when it comes to testing, using Jest and Enzyme, I always immediately get this error:

Test suite failed to run

    TypeError: L.markerClusterGroup is not a function

And the results always point right back to the line of

    const clusterItems = L.markerClusterGroup

I know others have had this same error, but normally that seems to happen when trying to run their project. In this case, I only get this error when trying to run tests. I've tried some ideas, like trying to use spyOn the clusterItems variable, mock an implementation, mock leaflet package, but no avail. And I can't find any specific case like this when looking around either.

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!