palantir/blueprint

Closing controlled Popover by clicking on target fails in tests because event.isTrusted is false

Open

#6,314 创建于 2023年8月3日

在 GitHub 查看
 (2 评论) (0 反应) (0 负责人)TypeScript (20,263 star) (2,167 fork)batch import
Domain: testingPackage: coreStatus: in discussionType: questionhelp wanted

描述

Hello, and thank you for the excellent library! I've found a problem that affects our tests. It's appeared recently and seems pretty straightforward.

Environment

  • Package version(s): "@blueprintjs/core": "^5.2.0", "@blueprintjs/datetime": "^5.0.8", "@blueprintjs/icons": "^5.1.5", "@blueprintjs/popover2": "^2.0.8",
  • Operating System: MacOS Ventura
  • Browser name and version: node

Steps to reproduce

  1. Write a test that tries to assert a controlled Popover closing on target click.

Actual behavior

Popover doesn't close.

Expected behavior

Popover closes and asserting that its contents disappeard passes.

Possible solution

I think the reason is this fix: https://github.com/palantir/blueprint/pull/6092 .

e.isTrusted is false in tests (we are using Jest). This makes this.isSimulatedButtonClick(e); true, which makes Popover ignore the click when trying to close it. Maybe your own test runner makes "real" clicks?

贡献者指南