# @commercetools/enzyme-extensions 中文文档

规范地址：https://npmcn.com/package/%40commercetools/enzyme-extensions/

版本：5\.0\.0
npm 元数据更新时间：2026-07-06T10:28:42.176Z
中文译文更新时间：2026-11-10T12:10:05.127Z
软件包许可：MIT

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

原始 npm 页面：https://www.npmjs.com/package/%40commercetools/enzyme-extensions
原文对照：https://npmcn.com/package/%40commercetools/enzyme-extensions/?lang=original
项目主页：https://github.com/commercetools/enzyme-extensions#readme
源码仓库：https://github.com/commercetools/enzyme-extensions

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

- 包体积（解压后）：13.7 kB，7 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：未声明
- Node.js 要求：\>=6
- 运行依赖：3 个
- peer 依赖：enzyme 3\.x
- 首次发布：2018-05-17T09:01:58.015Z
- 最新版本发布：2019-06-13T09:37:58.575Z
- 近 30 天下载量：7567（2026-10-11 至 2026-11-09，npm 官方下载统计）
- 已发布版本数：11（近 12 个月 0 个）

## 中文简介

适应于改进浅薄包装处理的酶扩展

## 安装

```sh
npm install @commercetools/enzyme-extensions
```

也可以使用：`pnpm add @commercetools/enzyme-extensions`、`yarn add @commercetools/enzyme-extensions`、`bun add @commercetools/enzyme-extensions`

## README

 [![commercetools logo](http://cdn.rawgit.com/commercetools/press-kit/master/PNG/72DPI/CT%20logo%20chrom%20black%20horizontal%20RGB%2072dpi.png)](https://commercetools.com/)**@ 商业工具/ enzyme- 扩展**  
  
![Logo](https://raw.githubusercontent.com/commercetools/enzyme-extensions/master/logo.jpeg)

 [![CircleCI Status](https://circleci.com/gh/commercetools/enzyme-extensions.svg?style=shield&circle-token=e58fc71dcfcab717a3ab1e529da76ab127d33a5e)](https://circleci.com/gh/commercetools/enzyme-extensions)[![Codecov Coverage Status](https://img.shields.io/codecov/c/github/commercetools/enzyme-extensions.svg?style=flat-square) ](https://codecov.io/gh/commercetools/enzyme-extensions)[![Downloads per Week](https://img.shields.io/npm/dw/@commercetools/enzyme-extensions.svg?style=flat-square) ](https://www.npmjs.com/package/@commercetools/enzyme-extensions)![Made with Coffee](https://img.shields.io/badge/made%20with-%E2%98%95%EF%B8%8F%20coffee-yellow.svg)  
  
你为什么要用这个? 读取: [测试一个Render道具!](https://medium.com/@dferber90/test-a-render-prop-6a44e02f4c39)  
  

> **页:1** 这个软件包用来提供 `renderProp` 测试帮助器, 其中 [现在属于 `enzyme` 本身](https://github.com/airbnb/enzyme/blob/master/CHANGELOG.md#380) 现改为:.
> 
> 因此我们放弃了 `renderProp` 在本包的v4.0.0中。 我们建议使用 `renderProp` 从酶本身取而代之.
> 
> 记住 [aPI 已经改变](https://github.com/airbnb/enzyme/pull/1891#issue-228765309) 同时将函数移动到酶中.
> 
> ```js
> // before
> wrapper.renderProp('foo', 10, 20);
> // after
> wrapper.renderProp('foo')(10, 20);
> ```
> 
> ![party-parrot](https://cultofthepartyparrot.com/parrots/parrot.gif) 我们很高兴我们的小帮手 已经做到了 `enzyme`。 。 。 .

## 这有什么假设?

-   我们 _喜欢浅出_ 并避免挂起
    -   浅色渲染速度快,并确保您只与 _正在测试的单位_
    -   \* \* \* 浅色渲染可确保您这样做 _没有快照过测试的担心_
    -   浅色渲染已经显示 _表现更强_ 对我们来说,比起升起
-   我们喜欢 _申报成分_ 财务报告和审定财务报表 _渲染道具_
    -   我们可以 _构成组件_ 很容易跟随互动
    -   我们喜欢 _出击_ 以测试单个逻辑片段

## 安装

### 1\. 添加包件

`yarn add @commercetools/enzyme-extensions -D`

### 2\. 添加测试设置文件( 取决于测试跑道)

对于杰斯特,你会设置 [`setupTestFrameworkScriptFile`](https://facebook.github.io/jest/docs/configuration.html#setuptestframeworkscriptfile-string)。 。 。 . 创建该文件并添加到游戏配置中 .

### 3\. 用此包的帮助扩展酶

在那个 `testFrameworkScriptFile` 文件,导入扩展名并添加到 Enzyme

```js
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-xx';
import configure from '@commercetools/enzyme-extensions';
import ShallowWrapper from 'enzyme/ShallowWrapper';

// You likely had this part already
Enzyme.configure({ adapter: new Adapter() });

// This is the actual integration.
// Behind the scenes this extends the prototype of the passed in `ShallowWrapper`
configure(ShallowWrapper);
```

## 使用量

一旦设置, 您可以使用您测试文件中的扩展名 :

```js
import React from 'react';
import { shallow } from 'enzyme';

describe('when rendering `<App>`', () => {
  const App = () => (
    <div id="app">
      <Mouse
        render={(x, y) => (
          <div>
            Cursor is at {x} {y}
          </div>
        )}
      />
    </div>
  );

  // Here we call the render function defined on Mouse and we provide
  // some custom arguments to it. This means we are effectively mocking
  // the Mouse component's implementation.
  // This is great to keep test concerns separate.
  const wrapper = shallow(<App />)
    .find(Mouse)
    // This is where we are actually using the drill function
    // Since we defined it on the prototype in the Installation step,
    // it does not need to be imported into the test itself.
    // We can call any property dynamically and even derive the property to
    // call depending on the props which are passed as the arguments of the
    // function passed to `drill`.
    .drill(props => props.render(10, 20));

  it('should render the mouse position', () => {
    expect(wrapper.equals(<div>Cursor is at 10 20</div>)).toBe(true);
  });
});
```

酶 `renderProp` 用于最常见的病例. 如果你需要更多的控制,你可以使用 `drill` 换句话说. `drill` 提供了更大的灵活性,例如:

-   从其他道具中可以得出道具
-   返回的元素可以动态设置

见 [`drill`](https://npmcn.com/package/%40commercetools/enzyme-extensions/docs/drill.md) 文档.

## 文档

-   [`drill`](https://npmcn.com/package/%40commercetools/enzyme-extensions/docs/drill.md)
-   [`until`](https://npmcn.com/package/%40commercetools/enzyme-extensions/docs/until.md)

## 常见问题

### @commercetools/enzyme-extensions 是什么？

适应于改进浅薄包装处理的酶扩展

### 如何安装 @commercetools/enzyme-extensions？

在项目目录运行 npm install @commercetools/enzyme-extensions，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：enzyme（3\.x）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @commercetools/enzyme-extensions 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/commercetools\_\_enzyme-extensions 是否存在。

### @commercetools/enzyme-extensions 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @commercetools/enzyme-extensions 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>=6。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @commercetools/enzyme-extensions 可以商用吗？

@commercetools/enzyme-extensions 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @commercetools/enzyme-extensions 的下载量有多少？

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

### @commercetools/enzyme-extensions 还在维护吗？

最新版本 5\.0\.0 发布于 2019/06/13（7 年前）；至今共发布 11 个版本，其中过去 12 个月发布了 0 个；首次发布于 2018/05/17。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

