@fluixi/testing

中文文档
1.0.0-alpha.108发布于 2026/11/07MITTypeScriptESM + CJS零依赖近 30 天下载 2016

Fluixi组件的最小测试帮助器——被制成jsdom,冲出效应,起火事件. 把vitest + @ testing-library/dom 带给其余部分.

中文使用文档
文档目录8 节
  1. 安装
  2. 使用
  3. API 密码
  4. render(code, options?) → RenderResult
  5. flush() → Promise<void>
  6. fireEvent(node, type, init?) → boolean
  7. 安全部门改革的说法
  8. 与 @ testing-library/ dom 连接

@fluixi/测试

用于测试 Fluixi 组件的最小帮助器. 它使一个组成部分成为 jsdom 容器,给你一个处理器和查询短手,再出口 flush 这样你就可以等待效果。 对于超过基础的询问和匹配者, 访问范围 @testing-library/dom数字 : 它和DOM有矛盾 所以它用盒子里的东西来编曲.

阿尔法。 这里的地表是故意小的, 更丰富的公用设施将会从 实际使用.

安装

npm i -D @fluixi/testing vitest jsdom

在jsdom的点:

// vitest.config.ts
import { defineConfig } from 'vitest/config';

export default defineConfig({
  test: { environment: 'jsdom', globals: true },
});

使用

import { render, flush, fireEvent } from '@fluixi/testing';
import { Counter } from './Counter';

it('increments on click', async () => {
  const { find, unmount } = render(() => <Counter start={2} />);

  expect(find('output')!.textContent).toBe('2');

  fireEvent(find('button')!, 'click');
  await flush(); // let effects settle

  expect(find('output')!.textContent).toBe('3');
  unmount();
});

API 密码

render(code, options?) → RenderResult

挂载 code (一个返回组件/元素的th)放入容器. 默认它会产生一个 <div> 并附加到 document.body; 通过 options.container 在别的地方上山.

RenderResult数字 :

  • container: 元素变成.
  • unmount():处理活性根并拆卸容器.
  • find(selector)数字 : container.querySelector。 。 。 .
  • findAll(selector)数字 : container.querySelectorAll,作为数组.
  • html(): 容器的电流 innerHTML。 。 。 .

flush() → Promise<void>

绒毛等待反应 另导出为 flushEffects。 。 。 .

fireEvent(node, type, init?) → boolean

可以取消的事件 讨论事项:Fluixi代表 on* 处理者,所以一个非bubbling事件不会到达他们。 对于任何富有, 使用情况 node.dispatchEvent(...) 直接或 @testing-library/dom是因为 fireEvent。 。 。 .

安全部门改革的说法

renderToString 用于声明服务器输出的再导出 :

import { renderToString } from '@fluixi/testing';

expect(renderToString(() => <Hello name="world" />)).toContain('world');

与 @ testing-library/ dom 连接

import { render } from '@fluixi/testing';
import { getByRole } from '@testing-library/dom';

const { container } = render(() => <LoginForm />);
getByRole(container, 'button', { name: /sign in/i }).click();

版本与发布记录

@fluixi/testing 共发布 56 个版本,首次发布于 2026/07/10;过去 12 个月发布了 56 个版本。

版本发布日期距今
1.0.0-alpha.108latest2026/11/078 天前
1.0.0-alpha.1072026/11/0511 天前
1.0.0-alpha.1062026/11/0213 天前
1.0.0-alpha.1052026/11/0115 天前
1.0.0-alpha.1042026/11/0115 天前
1.0.0-alpha.1032026/10/2620 天前

关于 @fluixi/testing 的常见问题

@fluixi/testing 是什么?

Fluixi组件的最小测试帮助器——被制成jsdom,冲出效应,起火事件. 把vitest + @ testing-library/dom 带给其余部分.

如何安装 @fluixi/testing?

在项目目录运行 npm install @fluixi/testing,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@fluixi/dom(^1.0.0-alpha.108)、@fluixi/reactive(^1.0.0-alpha.108)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@fluixi/testing 支持 TypeScript 吗?

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

@fluixi/testing 支持 ESM 还是 CommonJS?

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

@fluixi/testing 可以商用吗?

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

@fluixi/testing 的下载量有多少?

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

@fluixi/testing 还在维护吗?

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