用于 Google 地图的 Vitest Mocks
从 https://github.com/googlemaps/js-jest-mocks 互联网档案馆的存檔,存档日期2014-12-11
说明
Vitest为Google地图在TypeScript中进行取笑.
说明: 如果你找到一个丢失的模型 请打开一个 问题。 。 。 .
国家预防机制
国家防范机制作为一揽子方案提供 @anshulsanghi/googlemaps-vitest-mocks
检查嘲笑
您可以检查所创建的模拟实例发生的情况( 例如 ). Map 或者说 Marker通过 mockInstances 对象.
import {
initialize,
Map,
Marker,
mockInstances,
} from "@anshulsanghi/googlemaps-vitest-mocks";
beforeEach(() => {
initialize();
});
test("my test", () => {
const map = new google.maps.Map(null);
const markerOne = new google.maps.Marker();
const markerTwo = new google.maps.Marker();
map.setHeading(8);
markerOne.setMap(map);
markerTwo.setLabel("My marker");
const mapMocks = mockInstances.get(Map);
const markerMocks = mockInstances.get(Marker);
expect(mapMocks).toHaveLength(1);
expect(markerMocks).toHaveLength(2);
expect(mapMocks[0].setHeading).toHaveBeenCalledWith(8);
expect(markerMocks[0].setMap).toHaveBeenCalledTimes(1);
expect(markerMocks[1].setLabel).toHaveBeenCalledWith("My marker");
});
清理模拟器
无论何时 initialize() 被称作, 被捕获的模拟器自动清理。 使用Vitest的任何方法,你可以随时清理模拟实例:
import {
initialize,
Map,
Marker,
mockInstances,
} from "@anshulsanghi/googlemaps-vitest-mocks";
beforeAll(() => {
initialize();
});
// Clear all mocks
beforeEach(() => {
mockInstances.clearAll();
});
// Clear specific mocks
beforeEach(() => {
mockInstances.clear(Map, Marker);
});
支助
这个图书馆是社区支持的。 我们很适应 稳定与特点 我们想让你在上面 建立真正的生产应用程序的图书馆.
