javascript - 与 Leaflet Markercluster 开玩笑
问题描述
我在测试与 markerCluster 相关的内容时遇到问题。我正在使用 Leaflet.markercluster npm 包,版本 1.5.1。我正在使用以下导入做类似于 git 页面上的示例的操作:
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";
我正在写的变量:
const clusterItems = L.markerClusterGroup({
chunkedLoading: true,
showCoverageOnHover: false,
iconCreateFunction: customIcon,
removeOutsideVisibleBounds: true,
disableClusteringAtZoom:18
});
我也使用 react 作为我的前端库,如果你需要知道的话,可以使用 typescript。
问题是,在实际运行服务时工作正常。但是在使用 Jest 和 Enzyme 进行测试时,我总是会立即得到这个错误:
测试套件无法运行
TypeError: L.markerClusterGroup is not a function
并且结果总是指向正确的线
const clusterItems = L.markerClusterGroup
我知道其他人也有同样的错误,但通常在尝试运行他们的项目时似乎会发生这种情况。在这种情况下,我只在尝试运行测试时收到此错误。我尝试了一些想法,比如尝试使用 spyOn clusterItems 变量、模拟实现、模拟传单包,但无济于事。而且我环顾四周时也找不到任何这样的具体案例。
解决方案
推荐阅读
- c# - Kentico:下载文件上传到 cms
- discord - Discord 机器人如何只回复特定用户?
- python - 为什么我的 Pandas 绘图功能会在彼此之上绘制独立的数据集?
- python - Counting the many-to-many value in filter
- python - 正则表达式在字符串中查找一系列大写单词
- select - 作为谷歌表格查询的一部分,如何阻止upper()被拉出?
- java - 如何解决aosp中不允许的明文
- excel - 通过电子邮件发送活动工作簿但更改名称
- databricks - 如何限制对 Databricks 文件系统中特定路径的读/写访问?
- spring-boot - spring boot 2 + spring data jpa回滚事务