`@effect/ui-native` / `@effect/ui/testing` (Effect-TS/ui): `Locator.testId` only matches HTML `attrs["data-testid"]` and cannot locate React Native `.prop("testID", ...)`

未关闭
#11,079 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@effect-bot 已经在做这个了。

开始于 2026年11月29日。

  • #647 来自 @effect-bot —— 未关闭

评估

难度
3/5
预计耗时
半天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
react-native, typescript
领域
testing

调研方向

Start with packages/ui/src/testing/Locator.ts, where testId matches data-testid, and compare it with the native props described in the issue. Check the existing locator tests and the native testing exports in packages/ui-native/src/testing/index.ts. Done means Locator.testId("save-button") can find a node tagged through .prop("testID", "save-button") and the behavior is covered by a test; an open linked pull request is already addressing this issue.

由索引模型根据 Issue 内容生成。

描述

partially generated with help of my ai friend - neon 4.4

Hi effect team,
I was trying out this package and wanted to report some bugs encountered while porting a library to effect native

What version of Effect is running?
  • effect: 4.1.7
  • @effect/ui & @effect/ui-native: Effect-TS/ui main at 77391ee50ae3d3175d670facbf675e9a819ba6a6
  • react-native: 0.88.1
What steps can reproduce the bug?
  1. Clone the minimal reproduction repository:
    git clone https://github.com/cliffordfajardo/effectui-native-error-reproductions.git
    cd effectui-native-error-reproductions
    pnpm install
    pnpm test
    
  2. Render a Native.component that sets React Native's standard testID prop via .prop("testID", "save-button"):
const ActionButton = Native.component({
  name: "ActionButton",
  model: Schema.Number,
  message: Message
}).make({
  init: () => 0,
  update: {
    Pressed: ($) => $.model + 1
  },
  view: (h, count) =>
    h.view
      .prop("testID", "save-button")
      .on("press", () => Message.Pressed())
      .children(h.text.children(`Saved ${count}`))
})
  1. Query the rendered tree in a Play test using Locator.testId("save-button") (see 01-locator-testid-misses-native-props-testid/repro.test.ts).
What is the expected behavior?

Locator.testId("save-button") (or a native locator / Locator.prop(...) helper exported from @effect/ui/testing or @effect/ui-native/testing) should find native elements whose testID was set with .prop("testID", "save-button"), so Play and Scene tests can target native nodes by test ID without writing custom tree-walking locators.

What do you see instead?

packages/ui-native/src/Native.ts:668 defines readonly testID?: string | undefined on ViewProps, which writes to node.props.testID while leaving node.attrs empty.

However, packages/ui/src/testing/Locator.ts:188 implements testId strictly against HTML attributes:

export const testId = (id: string): Locator => attr("data-testid", id)

Even though Locator.Node (packages/ui/src/testing/Locator.ts:45-51) already models readonly props?: Readonly<Record<string, unknown>> | undefined, Locator.testId("save-button") returns [] for native views, causing play.expect(Locator.testId("save-button")).toExist() to fail.

Additionally, @effect/ui/testing does not export a Locator.prop(name, value) builder, and @effect/ui-native/testing (packages/ui-native/src/testing/index.ts) currently only exports TestDevice.

Additional information

In React Native / Fabric, .prop("testID", id) maps to native accessibility identifiers (e.g. accessibilityIdentifier on iOS) and is the idiomatic way to tag custom components for both component tests and native E2E tests.

Possible fixes:

  • Have Locator.testId(id) match either node.attrs?.["data-testid"] === id or node.props?.testID === id, and/or
  • Export Locator.prop(name, value?) from @effect/ui/testing (and optionally a NativeLocator.testID helper from @effect/ui-native/testing).
主要语言
TypeScript
星标
16.7k
派生
808
平均合并
21 小时 22 分钟
30 天内合并 PR
486

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Effect-TS/effect 的其他 Issue

查看 Effect-TS/effect 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。