# @1024pix/ember-testing-library 中文文档

规范地址：https://npmcn.com/package/%401024pix/ember-testing-library/

版本：4\.0\.1
npm 元数据更新时间：2026-09-30T10:15:05.688Z
中文译文更新时间：2026-11-05T23:02:41.158Z
软件包许可：AGPL-3\.0

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

原始 npm 页面：https://www.npmjs.com/package/%401024pix/ember-testing-library
原文对照：https://npmcn.com/package/%401024pix/ember-testing-library/?lang=original
源码仓库：https://github.com/1024pix/pix-ui-libs

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

- 包体积（解压后）：11.2 kB，4 个文件
- 模块格式：ES Module
- TypeScript 类型：未声明
- 运行依赖：0 个
- peer 依赖：@ember/test-helpers \>=5，@testing-library/dom \>=10
- 首次发布：2021-10-27T15:36:26.921Z
- 最新版本发布：2026-09-30T10:15:05.323Z
- 近 30 天下载量：10039（2026-10-04 至 2026-11-02，npm 官方下载统计）
- 已发布版本数：67（近 12 个月 19 个）

## 中文简介

在 Ember 应用程序中测试库使用的软件包 .

## 安装

```sh
npm install @1024pix/ember-testing-library
```

也可以使用：`pnpm add @1024pix/ember-testing-library`、`yarn add @1024pix/ember-testing-library`、`bun add @1024pix/ember-testing-library`

## README

# @1024pix/ember-测试-图书馆

Ember测试库是用于测试Ember组件的非常轻量级的解决方案. 它在Ember内置帮助器上提供轻便的功能,鼓励更好的测试做法. 其主要指导原则是:

-   你的测试越像 你的软件使用的方式, 他们可以给你更多的信心.

更多信息,请访问 [测试图书馆指导原则](https://testing-library.com/docs/guiding-principles)。 。 。 .

## 安装

```sh
npm install -D @1024pix/ember-testing-library @testing-library/dom @ember/test-helpers
```

## 使用量

Ember测试库允许在 Ember app中访问 Dom测试库查询. 关于 dom 测试库查询的更多信息,请查询 [测试库文件](https://testing-library.com/docs/dom-testing-library/api/)。 。 。 .

目前可以使用的API方法如下:

-   获取史克林
-   在内部
-   访问
-   提交
-   单击ByName
-   点击文字
-   填充标签
-   选择标签和选项
-   选择可选的无线电组
-   获得 ByTextWithHtml
-   获取 AllByTextWithHtml 数据
-   查询ByTextWithHtml
-   查询 AllByTextWithHtml
-   找到 ByText With Html 数据
-   找到 AllByTextWithHtml 数据

请注意,Ember测试库不包括: `userEvent` 软件包,因此您应该使用 Ember 内置测试帮助器在集成/接受测试中与组件和/或DOM节点交互.

### 接受测试实例 :

```js
import { visit } from '@1024pix/ember-testing-library';
import { click } from '@ember/test-helpers';

test('it should disable the button when clicked', async function (assert) {
  // given
  const screen = await visit('/home');

  // when
  const button = screen.getByRole('button', { name: 'Send message' });
  await click(button);

  // then
  assert.dom(button).isDisabled();
});
```

### 整合测试实例 :

```js
import { render } from '@1024pix/ember-testing-library';
import { click } from '@ember/test-helpers';

test('it should disable the button when clicked', async function (assert) {
  // given
  const screen = await render(hbs`<LoginForm />`);

  // when
  const button = screen.getByRole('button', { name: 'Login' });
  await click(button);

  // then
  assert.dom(button).isDisabled();
});
```

## 常见问题

### @1024pix/ember-testing-library 是什么？

在 Ember 应用程序中测试库使用的软件包 \.

### 如何安装 @1024pix/ember-testing-library？

在项目目录运行 npm install @1024pix/ember-testing-library，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：@ember/test-helpers（\>=5）、@testing-library/dom（\>=10）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @1024pix/ember-testing-library 支持 TypeScript 吗？

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

### @1024pix/ember-testing-library 支持 ESM 还是 CommonJS？

以 ES Module 形式发布，推荐使用 import 引入。在 CommonJS 项目中，Node\.js 20\.19\+ / 22\.12\+ 可以直接 require\(\) 不含顶层 await 的 ES Module，更早的版本需要改用动态 import\(\)。

### @1024pix/ember-testing-library 可以商用吗？

@1024pix/ember-testing-library 使用 AGPL-3\.0 许可。最严格的 Copyleft：除分发外，通过网络向用户提供基于它的服务也需要开源对应源码。闭源 SaaS 使用前务必评估。以上为概括，不构成法律意见，请以许可原文为准。

### @1024pix/ember-testing-library 的下载量有多少？

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

### @1024pix/ember-testing-library 还在维护吗？

最新版本 4\.0\.1 发布于 2026/09/30（1 个月前）；至今共发布 67 个版本，其中过去 12 个月发布了 19 个；首次发布于 2021/10/27。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

