# @dynatrace/strato-components-testing 中文文档

规范地址：https://npmcn.com/package/%40dynatrace/strato-components-testing/

版本：3\.18\.0
npm 元数据更新时间：2026-11-13T07:47:01.510Z
中文译文更新时间：2026-11-14T02:03:14.685Z
软件包许可：Apache-2\.0

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

原始 npm 页面：https://www.npmjs.com/package/%40dynatrace/strato-components-testing
原文对照：https://npmcn.com/package/%40dynatrace/strato-components-testing/?lang=original

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

- 包体积（解压后）：571 kB，255 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：0 个
- peer 依赖：jest ^29\.0\.0 \|\| ^30\.0\.0，react ^18\.0\.0 \|\| ^19\.0\.0，vitest ^1\.0\.0 \|\| ^2\.0\.0 \|\| ^3\.0\.0 \|\| ^4\.0\.0 \|\| ^5\.0\.0，react-dom ^18\.0\.0 \|\| ^19\.0\.0，type-fest ^5\.0\.0，react-intl ^6\.0\.8 \|\| ^7\.0\.0，framer-motion ^11\.3\.19 \|\| ^12\.0\.0，@testing-library/react ^16\.0\.0，@testing-library/user-event ^14\.0\.0，@dynatrace/strato-components ^3\.18\.0
- 首次发布：2025-01-29T09:04:24.959Z
- 最新版本发布：2026-11-13T07:47:01.268Z
- 近 30 天下载量：2579（2026-10-13 至 2026-11-11，npm 官方下载统计）
- 已发布版本数：91（近 12 个月 70 个）

## 中文简介

此软件包包含测试助手 `@dynatrace/strato-components` 软件包.

## 安装

```sh
npm install @dynatrace/strato-components-testing
```

也可以使用：`pnpm add @dynatrace/strato-components-testing`、`yarn add @dynatrace/strato-components-testing`、`bun add @dynatrace/strato-components-testing`

## README

# Strato 组件测试

此软件包包含测试助手 `@dynatrace/strato-components` 软件包.

## 欢乐

### 配置

此测试软件包包含一个会配置 jest 的预设, 以配合 `@dynatrace/strato-components` 软件包。 您可以在您的预设中添加 `jest.config.js` 这样的文件 :

```js
const {
  stratoPreset,
} = require('@dynatrace/strato-components-testing/jest/preset');

/** @type {import('jest').Config} */
module.exports = {
  ...stratoPreset,
  // your config
  ...
  // your per test setup
  setupFilesAfterEnv: [
    '@dynatrace/strato-components-testing/jest/setup',
  // your per test setup
    "./jest.setup-env.ts"
  ],
  moduleNameMapper: {
    ...stratoPreset.moduleNameMapper,
    // your other moduleNameMappers
  },
};
```

### 设置

设置在 `@dynatrace/strato-components-testing/jest/setup`,您在上面配置的.

但你也可以设置或清除个人的模拟:

```ts
import {
  setupScreenSizeMock,
  clearScreenSizeMock,
} from '@dynatrace/strato-components-testing/jest';

// use where needed
```

### 测试助手

此包还包含测试助手.

#### 测试帮助者是什么?

测试助手是帮助您在测试中选择和与组件交互的功能,所以您不必依赖组件的多姆,比如 `role`, (中文(简体) ), `label`,或 `test-id`。 。 。 .

#### 使用量

请注意,这个测试包还没有帮助者. 一旦有帮手,你就会像这样使用他们:

```tsx
import {
  render,
  getTextInputHelper,
} from '@dynatrace/strato-components-testing/jest';
import { TextInput } from '@dynatrace/strato-components/forms';

it('test', async () => {
  render(
    <TextInput
      aria-label="test input"
      data-testid="text-input-test"
      placeholder="Test input"
    />,
  );

  await getTextInputHelper('text-input-test').type('abc');
  expect(getTextInputHelper('text-input-test').value).toEqual('abc');
});
```

#### 测试钩

`renderHook` 将钩子装入相同的提供者 `render` (单位:千美元)`IntlProvider` 与 `locale="en"` 财务报告和审定财务报表 `timeZone="UTC"` (默认)和接受相同的 `locale`, (中文(简体) ), `timeZone`,以及 `wrapper` 选项。 这两份文件都提供了 `jest` 财务报告和审定财务报表 `vitest` 进入点.

```tsx
import { renderHook } from '@dynatrace/strato-components-testing/jest';

it('formats with the active locale', () => {
  const { result } = renderHook(() => useMyHook(), { locale: 'de' });
  expect(result.current).toEqual('1,5');
});
```

## 常见问题

### @dynatrace/strato-components-testing 是什么？

此软件包包含测试助手 @dynatrace/strato-components 软件包\.

### 如何安装 @dynatrace/strato-components-testing？

在项目目录运行 npm install @dynatrace/strato-components-testing，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：react（^18\.0\.0 \|\| ^19\.0\.0）、react-dom（^18\.0\.0 \|\| ^19\.0\.0）、type-fest（^5\.0\.0）、react-intl（^6\.0\.8 \|\| ^7\.0\.0）、framer-motion（^11\.3\.19 \|\| ^12\.0\.0）、@testing-library/react（^16\.0\.0）、@testing-library/user-event（^14\.0\.0）、@dynatrace/strato-components（^3\.18\.0）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @dynatrace/strato-components-testing 支持 TypeScript 吗？

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

### @dynatrace/strato-components-testing 支持 ESM 还是 CommonJS？

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

### @dynatrace/strato-components-testing 可以商用吗？

@dynatrace/strato-components-testing 使用 Apache-2\.0 许可。宽松许可：允许商业使用、修改和再分发，并附带明确的专利授权；分发时需保留许可与 NOTICE 文件，修改过的文件要注明改动。以上为概括，不构成法律意见，请以许可原文为准。

### @dynatrace/strato-components-testing 的下载量有多少？

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

### @dynatrace/strato-components-testing 还在维护吗？

最新版本 3\.18\.0 发布于 2026/11/13（今天）；至今共发布 91 个版本，其中过去 12 个月发布了 70 个；首次发布于 2025/01/29。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

