@anshulsanghi/googlemaps-vitest-mocks

中文文档
1.0.1发布于 2022/09/02Apache-2.0TypeScriptCommonJS零依赖近 30 天下载 5707
原始使用文档
文档目录6 节
  1. Forked from https://github.com/googlemaps/js-jest-mocks
  2. Description
  3. NPM
  4. Inspecting mocks
  5. Cleaning up mocks
  6. Support

Vitest Mocks for Google Maps

Forked from https://github.com/googlemaps/js-jest-mocks

npm Build Release codecov GitHub contributors semantic-release Discord

Description

Vitest mocks for Google Maps in TypeScript.

Note: If you find a missing mock, please open an issue.

NPM

Available via NPM as the package @anshulsanghi/googlemaps-vitest-mocks

Inspecting mocks

You can inspect what happens with the created mock instances (e.g. Map or Marker) via the mockInstances object.

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");
});

Cleaning up mocks

Whenever initialize() is called, the captured mocks are automatically cleaned. Using any of Vitest's methods, you can clean the mock instances at any time:

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);
});

Support

This library is community supported. We're comfortable enough with the stability and features of the library that we want you to build real production applications on it.

If you find a bug, or have a feature suggestion, please log an issue. If you'd like to contribute, please read How to Contribute.

版本与发布记录

@anshulsanghi/googlemaps-vitest-mocks 共发布 2 个版本,首次发布于 2022/09/02;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.1latest2022/09/024 年前
1.0.02022/09/024 年前

关于 @anshulsanghi/googlemaps-vitest-mocks 的常见问题

@anshulsanghi/googlemaps-vitest-mocks 是什么?

Forked from https://github.com/googlemaps/js-jest-mocks

如何安装 @anshulsanghi/googlemaps-vitest-mocks?

在项目目录运行 npm install @anshulsanghi/googlemaps-vitest-mocks,或使用 pnpm add / yarn add / bun add。

@anshulsanghi/googlemaps-vitest-mocks 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@anshulsanghi/googlemaps-vitest-mocks 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@anshulsanghi/googlemaps-vitest-mocks 可以商用吗?

@anshulsanghi/googlemaps-vitest-mocks 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@anshulsanghi/googlemaps-vitest-mocks 的下载量有多少?

根据 npm 官方下载统计,@anshulsanghi/googlemaps-vitest-mocks 在 2026/10/06 – 2026/11/04 这 30 天内被下载 5,707 次,日均约 190 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@anshulsanghi/googlemaps-vitest-mocks 还在维护吗?

最新版本 1.0.1 发布于 2022/09/02(4 年前);至今共发布 2 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/09/02。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。