@dynatrace/strato-components-testing

中文文档
3.18.0发布于 2026/11/13Apache-2.0TypeScriptESM + CJS零依赖近 30 天下载 2579

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

中文使用文档
文档目录4 节
  1. 欢乐
  2. 配置
  3. 设置
  4. 测试助手

Strato 组件测试

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

欢乐

配置

此测试软件包包含一个会配置 jest 的预设, 以配合 @dynatrace/strato-components 软件包。 您可以在您的预设中添加 jest.config.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,您在上面配置的.

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

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

// use where needed

测试助手

此包还包含测试助手.

测试帮助者是什么?

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

使用量

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

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 进入点.

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 共发布 91 个版本,首次发布于 2025/01/29;过去 12 个月发布了 70 个版本。

版本发布日期距今
3.18.0latest2026/11/13今天
3.13.92026/11/049 天前
3.14.72026/11/049 天前
3.17.12026/11/049 天前
3.16.22026/11/049 天前
3.15.52026/11/049 天前

其他发布通道:backport-3.8.3 → 3.8.3,backport-3.9.2 → 3.9.2,backport-3.11.4 → 3.11.4,backport-3.13.3 → 3.13.3,backport-3.13.4 → 3.13.4,backport-3.13.5 → 3.13.5。

关于 @dynatrace/strato-components-testing 的常见问题

@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 和提交记录判断。