# miniprogram-simulate

> tools for miniprogram custom component unit test

Latest version **1.6.2** (published 2026-06-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install miniprogram-simulate
pnpm add miniprogram-simulate
yarn add miniprogram-simulate
bun add miniprogram-simulate
```

## Health

**Score 60/100 (C)** — status: active.

Positive: has types; no vulnerabilities; recently updated; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 1.6.2 |
| Published | 2026-06-29 |
| First published | 2018-12-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 1.9 MB |
| Known vulnerabilities | 0 (+5 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 536 |
| Author | wechat-miniprogram |
| Maintainers | wechat-miniprogram, juneandgreen |
| Keywords | miniprogram, custom component, unit test |

## Links

- npm: https://www.npmjs.com/package/miniprogram-simulate
- Repository: https://github.com/wechat-miniprogram/miniprogram-simulate
- Homepage: https://github.com/wechat-miniprogram/miniprogram-simulate#readme
- Issues: https://github.com/wechat-miniprogram/miniprogram-simulate/issues
- npm.io page: https://npm.io/package/miniprogram-simulate

## Dependencies (6)

- [csso](https://npm.io/package/csso.md) ^3.5.1
- [less](https://npm.io/package/less.md) ^3.10.3
- [postcss](https://npm.io/package/postcss.md) ^7.0.23
- [j-component](https://npm.io/package/j-component.md) ^1.4.10
- [pretty-format](https://npm.io/package/pretty-format.md) ^26.0.1
- [miniprogram-compiler](https://npm.io/package/miniprogram-compiler.md) latest

## Recent versions

- 1.6.2 (latest) — 2026-06-29
- 1.6.1 — 2023-08-31
- 1.6.0 — 2023-07-04
- 1.5.9 — 2023-03-01
- 1.5.8 — 2022-12-28
- 1.5.7 — 2022-05-19
- 1.5.6 — 2022-05-09
- 1.5.5 — 2022-03-07
- 1.5.4 — 2022-03-07
- 1.5.3 — 2022-03-04
- 1.5.2 — 2022-03-04
- 1.5.1 — 2022-02-18
- 1.5.0 — 2022-02-17
- 1.4.4 — 2022-01-17
- 1.4.3 — 2021-11-23
- … 46 more at https://npm.io/package/miniprogram-simulate/versions

## README

# miniprogram-simulate

[![](https://img.shields.io/npm/v/miniprogram-simulate.svg?style=flat)](https://www.npmjs.com/package/miniprogram-simulate)
[![](https://github.com/wechat-miniprogram/miniprogram-simulate/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/wechat-miniprogram/miniprogram-simulate/actions/workflows/ci.yml?query=branch%3Amaster+)
[![](https://img.shields.io/github/license/wechat-miniprogram/miniprogram-simulate.svg)](https://github.com/wechat-miniprogram/miniprogram-simulate/blob/master/LICENSE)
[![](https://img.shields.io/codecov/c/github/wechat-miniprogram/miniprogram-simulate.svg)](https://app.codecov.io/gh/wechat-miniprogram/miniprogram-simulate)

## 介绍

小程序自定义组件测试工具集。

目前因为小程序独特的运行环境，所以对于小程序自定义组件的单元测试一直没有比较优雅的解决方案，此工具集就是为了解决此痛点而诞生的。将原本小程序自定义组件双线程分离运行的机制调整成单线程模拟运行，利用 dom 环境进行渲染，借此来完成整个自定义组件树的搭建。

运行此工具集需要依赖 js 运行环境和 dom 环境，因此可以采用 jsdom + nodejs（如 jest），也可以采用真实浏览器环境（如 karma）。文档[使用简介](./docs/tutorial.md)中会提供简单的使用方式介绍。

## 安装

```
npm install --save-dev miniprogram-simulate
```

## 使用

```js
const simulate = require('miniprogram-simulate')

test('test sth', () => {
    const id = simulate.load('/components/comp/index') // 加载自定义组件
    const comp = simulate.render(id) // 渲染自定义组件
    
    // 使用自定义组件封装实例 comp 对象来进行各种单元测试
})
```

以上只是一个简单的例子，实际上这个工具集必须搭配 jest 或 jsdom/mocha 等测试框架来使用，更为详细的使用细节请参阅下述文档：

* [使用简介](./docs/tutorial.md)
* [接口文档](./docs/api.md)
* [细节实现](./docs/detail.md)
* [暂不支持特性](./docs/todo.md)
* [更新日志](./docs/update.md)

## 协议

[MIT](./LICENSE)

---
_Source: https://npm.io/package/miniprogram-simulate · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
