@atomic-testing/react-18

中文文档
0.104.0发布于 2026/08/20MITTypeScriptESM + CJS构建来源已验证近 30 天下载 3225

Adapter for integrating Atomic Testing with React 18. It maps React components to the core scene part APIs.

原始使用文档
文档目录5 节
  1. The problem
  2. The solution
  3. Installation
  4. Example
  5. Public API & stability

@atomic-testing/react-18

Adapter for integrating Atomic Testing with React 18. It maps React components to the core scene part APIs.

The problem

Writing maintainable tests for UIs built with third–party component libraries like Material UI or Bootstrap can be tricky. Documentation on how a test should communicate with these components is often lacking, so tests easily end up coupled to implementation details. As your application grows you need your tests to scale without constantly reworking them.

The solution

Atomic Testing provides a consistent way to interact with both third–party and first–party components across different test environments. It focuses on reusability, composability and adaptability, letting you build higher–level test strategies that work for DOM or end–to–end testing alike.

Installation

npm install @atomic-testing/core @atomic-testing/react-18 --save-dev

Refer to the React integration guide for examples.

Example

If you use MUI/Material UI components, have a look at the @atomic-testing/component-driver-mui-v7 package for a dedicated example.

  1. Install the core library and basic HTML drivers along with this React adapter:

    npm install @atomic-testing/core @atomic-testing/react-18 @atomic-testing/component-driver-html --save-dev
    
  2. Create a small component and assign data-testid values to the elements you want to interact with:

    import { useState } from 'react';
    
    export function Counter() {
      const [count, setCount] = useState(0);
      return (
        <div>
          <span data-testid='count'>{count}</span>
          <button data-testid='increment' onClick={() => setCount(c => c + 1)}>
            Increment
          </button>
        </div>
      );
    }
    
  3. Define a ScenePart describing the count display and button using the HTML drivers:

    import { HTMLButtonDriver, HTMLElementDriver } from '@atomic-testing/component-driver-html';
    import { byDataTestId, ScenePart } from '@atomic-testing/core';
    
    export const counterScenePart = {
      count: { locator: byDataTestId('count'), driver: HTMLElementDriver },
      increment: { locator: byDataTestId('increment'), driver: HTMLButtonDriver },
    } satisfies ScenePart;
    
  4. Write a test using createTestEngine to render the component and interact with it:

     import { createTestEngine } from '@atomic-testing/react-18';
    
     import { Counter } from './Counter';
     import { counterScenePart } from './counterScenePart';
    
     test('increments when the button is clicked', async () => {
       const engine = createTestEngine(<Counter />, counterScenePart);
    
       expect(await engine.parts.count.getText()).toBe('0');
       await engine.parts.increment.click();
       expect(await engine.parts.count.getText()).toBe('1');
    
       await engine.cleanUp();
     });
    

For more in‑depth information, visit https://atomic-testing.dev.

Public API & stability

The stable surface of this package is its . barrel exports, frozen under SemVer and machine-checked by the committed API Extractor report at etc/react-18.api.md. Exports tagged @internal are not part of that guarantee. See the 1.0 API freeze & evolution policy.

版本与发布记录

@atomic-testing/react-18 共发布 30 个版本,首次发布于 2025/06/18;过去 12 个月发布了 22 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.104.0latest2026/08/202 个月前
0.103.02026/08/182 个月前
0.102.02026/08/172 个月前
0.101.02026/08/073 个月前
0.100.02026/08/023 个月前
0.99.02026/07/223 个月前

关于 @atomic-testing/react-18 的常见问题

@atomic-testing/react-18 是什么?

Adapter for integrating Atomic Testing with React 18. It maps React components to the core scene part APIs.

如何安装 @atomic-testing/react-18?

在项目目录运行 npm install @atomic-testing/react-18,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@testing-library/dom(>=10.4.1)、@testing-library/react(>=16.2.0)、@testing-library/user-event(>=14.0.0)、react(>=18.0.0 <19.0.0)、react-dom(>=18.0.0 <19.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@atomic-testing/react-18 支持 TypeScript 吗?

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

@atomic-testing/react-18 支持 ESM 还是 CommonJS?

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

@atomic-testing/react-18 可以商用吗?

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

@atomic-testing/react-18 的下载量有多少?

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

@atomic-testing/react-18 还在维护吗?

最新版本 0.104.0 发布于 2026/08/20(2 个月前);至今共发布 30 个版本,其中过去 12 个月发布了 22 个;首次发布于 2025/06/18。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。