palantir / blueprint

A React-based UI toolkit for the web
https://blueprintjs.com/
Apache License 2.0
20.71k stars 2.17k forks source link

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

Open snps-halkoaho opened 1 year ago

snps-halkoaho commented 1 year ago

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

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?

adidahiya commented 1 year ago

Maybe your own test runner makes "real" clicks?

Our testing suite uses both simulated and real click events. Is it possible to set the isTrusted property via Jest APIs?

snps-halkoaho commented 1 year ago

@adidahiya As far as I understand, it's not possible to set isTrusted to be true in Jest.