-
Notifications
You must be signed in to change notification settings - Fork 301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
filterTaps disables all click events in Jest #418
Comments
Hey, thanks for reporting this. The use-gesture/packages/core/src/engines/DragEngine.ts Lines 231 to 236 in 9217f29
So I'm not sure how I would be able to solve this. Shouldn't this be a bug in Jest instead? |
After some further investigation I found out that There is a helper library which triggers a full click which works: import userEvent from '@testing-library/user-event';
userEvent.click() Could we set |
Oh right. You mean setting I'd have to make sure there's no collaterals. |
Rather here:
For normal browsers this shouldn't have any effect as it will be set to a correct value in |
Yes, that's what I meant, but I would have to restore |
Oh I see - good point |
For anyone coming here wanting to trigger the fireEvent.mouseDown(element, { buttons: 1 });
fireEvent.mouseUp(element, { buttons: 1 }); The This is a more complete example of what's working for me using import { fireEvent } from '@testing-library/react';
const click: typeof fireEvent.click = (element, options) => {
const _options: Record<string, any> = options ?? {};
if (!_options.buttons) {
// default to left mouse button
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons
_options.buttons = 1;
}
return fireEvent.mouseDown(element, _options) && fireEvent.mouseUp(element, _options);
}; Here's how |
Describe the bug
the
filterTaps
option works great in all browser however in JEST it prevents child listeners from working.I am only guessing but maybe the following line doesn't work well as JEST is not able to get real size measurements:
use-gesture/packages/core/src/engines/DragEngine.ts
Line 210 in 9217f29
Sandbox or Video
I prepared this CodeSandbox with unit tests.
It contains Demo1 and Demo2:
As you can see the only difference is
filterTaps: true
.The result is that the unit test which tries to click the button fails for Demo2:
Checklist:
The text was updated successfully, but these errors were encountered: