# @anshulsanghi/googlemaps-vitest-mocks 中文文档

规范地址：https://npmcn.com/package/%40anshulsanghi/googlemaps-vitest-mocks/

版本：1\.0\.1
npm 元数据更新时间：2022-09-02T10:51:26.949Z
中文译文更新时间：2026-11-06T05:50:15.437Z
软件包许可：Apache-2\.0

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40anshulsanghi/googlemaps-vitest-mocks
原文对照：https://npmcn.com/package/%40anshulsanghi/googlemaps-vitest-mocks/?lang=original
项目主页：https://github.com/anshap1719/js-vitest-mocks
源码仓库：https://github.com/anshap1719/js-vitest-mocks

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：117 kB，49 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- 运行依赖：0 个
- 首次发布：2022-09-02T10:40:11.305Z
- 最新版本发布：2022-09-02T10:51:26.873Z
- 近 30 天下载量：5707（2026-10-06 至 2026-11-04，npm 官方下载统计）
- 已发布版本数：2（近 12 个月 0 个）

## 中文简介

## 从 [https://github.com/googlemaps/js-jest-mocks 互联网档案馆的存檔,存档日期2014-12-11](https://github.com/googlemaps/js-jest-mocks)

## 安装

```sh
npm install @anshulsanghi/googlemaps-vitest-mocks
```

也可以使用：`pnpm add @anshulsanghi/googlemaps-vitest-mocks`、`yarn add @anshulsanghi/googlemaps-vitest-mocks`、`bun add @anshulsanghi/googlemaps-vitest-mocks`

## README

# 用于 Google 地图的 Vitest Mocks

## 从 [https://github.com/googlemaps/js-jest-mocks 互联网档案馆的存檔,存档日期2014-12-11](https://github.com/googlemaps/js-jest-mocks)

[![npm](https://img.shields.io/npm/v/@anshulsanghi/googlemaps-vitest-mocks)](https://www.npmjs.com/package/@anshulsanghi/googlemaps-vitest-mocks) ![Build](https://github.com/anshap1719/js-vitest-mocks/workflows/Test/badge.svg) ![Release](https://github.com/anshap1719/js-vitest-mocks/workflows/Release/badge.svg) [![codecov](https://codecov.io/gh/anshap1719/js-vitest-mocks/branch/main/graph/badge.svg)](https://codecov.io/gh/anshap1719/js-vitest-mocks) ![GitHub contributors](https://img.shields.io/github/contributors/anshap1719/js-vitest-mocks?color=green) [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release) [![](https://github.com/jpoehnelt/in-solidarity-bot/raw/main/static//badge-flat.png)](https://github.com/apps/in-solidarity) [![Discord](https://img.shields.io/discord/676948200904589322?color=6A7EC2&logo=discord&logoColor=ffffff)](https://discord.gg/jRteCzP)

## 说明

Vitest为Google地图在TypeScript中进行取笑.

**说明:** 如果你找到一个丢失的模型 请打开一个 [问题](https://github.com/anshap1719/js-vitest-mocks/issues)。 。 。 .

## 国家预防机制

国家防范机制作为一揽子方案提供 `@anshulsanghi/googlemaps-vitest-mocks`

## 检查嘲笑

您可以检查所创建的模拟实例发生的情况( 例如 ). `Map` 或者说 `Marker`通过 `mockInstances` 对象.

```ts
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的任何方法,你可以随时清理模拟实例:

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

## 支助

这个图书馆是社区支持的。 我们很适应 稳定与特点 我们想让你在上面 建立真正的生产应用程序的图书馆.

如果您发现错误, 或者有特性建议, 请 [日志一个问题](https://github.com/anshap1719/js-vitest-mocks/issues)如果你愿意的话 请填写 [如何贡献](https://npmcn.com/package/%40anshulsanghi/googlemaps-vitest-mocks/CONTRIBUTING.md)。 。 。 .

## 常见问题

### @anshulsanghi/googlemaps-vitest-mocks 是什么？

从 https://github\.com/googlemaps/js-jest-mocks 互联网档案馆的存檔,存档日期2014-12-11

### 如何安装 @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 和提交记录判断。

