palantir/blueprint

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

Open

#6314 opened on Aug 3, 2023

View on GitHub
 (2 comments) (0 reactions) (0 assignees)TypeScript (20,263 stars) (2,167 forks)batch import
Domain: testingPackage: coreStatus: in discussionType: questionhelp wanted

Description

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?

Contributor guide