【问题标题】:Mocking google.maps.LatLng in jest开玩笑地嘲笑 google.maps.LatLng
【发布时间】:2022-01-26 23:51:50
【问题描述】:

我正在为谷歌地图使用热图图层,在为热图映射数据时,我正在使用构造函数 new google.maps.LatLng(lat, lng),一切正常文件。在 index.html 文件中,我已经加载了 //maps.googleapis.com/maps/api... 我想这就是我获得全局 google 对象的地方,我可以使用它调用该构造函数。

所以真正的问题是当我尝试使用 Jest 编写单元测试时。 我收到 google 未在全局中定义的消息。

我尝试在测试设置中模拟 global.google,但无法完成。

【问题讨论】:

    标签: unit-testing google-maps jestjs mocking


    【解决方案1】:

    使用https://www.npmjs.com/package/@googlemaps/jest-mocks

    import { initialize } from "@googlemaps/jest-mocks";
    
    beforeEach(() => {
      initialize();
    });
    
    // Your tests
    
    

    【讨论】:

      猜你喜欢
      • 2021-06-20
      • 1970-01-01
      • 2019-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-02
      • 1970-01-01
      • 2018-12-07
      相关资源
      最近更新 更多