@atomic-testing/component-driver-mui-v5

中文文档
0.81.0发布于 2026/01/01MITTypeScriptESM + CJS近 30 天下载 3320

Atomic Testing Component driver to help drive Material UI v5 components

原始使用文档
文档目录4 节
  1. The problem
  2. The solution
  3. Installation
  4. Example

@atomic-testing/component-driver-mui-v5

Component drivers for Material UI v5 components. Component drivers expose simple APIs for unit tests or end‑to‑end tests to interact with MUI components—such as reading states and setting values—so test engineers can focus on test flows without needing to track how the inner MUI components work.

The problem

Material UI hides complex markup behind its components. Without dedicated drivers your tests often need to rely on implementation details, making them brittle as your application grows.

The solution

The drivers in this package expose high‑level interactions for MUI widgets. Combined with the React adapter, they let you reuse scene definitions across DOM and end‑to‑end tests, focusing on reusability, composability and adaptability.

Installation

npm install @atomic-testing/core @atomic-testing/react-19 \
  @atomic-testing/component-driver-html @atomic-testing/component-driver-mui-v5 --save-dev

Refer to the MUI driver guide for examples.

Example

  1. Create a small component using MUI and assign data-testid values to the elements you want to interact with:

    import { useState } from 'react';
    
    import Button from '@mui/material/Button';
    
    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>
      );
    }
    
  2. Define a ScenePart describing the count display and button using the MUI driver:

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

    import { createTestEngine } from '@atomic-testing/react-19';
    
    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.

版本与发布记录

@atomic-testing/component-driver-mui-v5 共发布 80 个版本,首次发布于 2023/03/11;过去 12 个月发布了 3 个版本。

版本发布日期距今
0.81.0latest2026/01/0110 个月前
0.80.02025/12/3010 个月前
0.79.02025/12/3010 个月前
0.78.02025/06/301.4 年前
0.77.02025/06/291.4 年前
0.76.02025/06/231.4 年前

关于 @atomic-testing/component-driver-mui-v5 的常见问题

@atomic-testing/component-driver-mui-v5 是什么?

Atomic Testing Component driver to help drive Material UI v5 components

如何安装 @atomic-testing/component-driver-mui-v5?

在项目目录运行 npm install @atomic-testing/component-driver-mui-v5,或使用 pnpm add / yarn add / bun add。

@atomic-testing/component-driver-mui-v5 支持 TypeScript 吗?

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

@atomic-testing/component-driver-mui-v5 支持 ESM 还是 CommonJS?

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

@atomic-testing/component-driver-mui-v5 可以商用吗?

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

@atomic-testing/component-driver-mui-v5 的下载量有多少?

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

@atomic-testing/component-driver-mui-v5 还在维护吗?

最新版本 0.81.0 发布于 2026/01/01(10 个月前);至今共发布 80 个版本,其中过去 12 个月发布了 3 个;首次发布于 2023/03/11。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。