Skip to content

docs: fix fireEvent Example code #1019

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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions docs/preact-testing-library/api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,13 @@ fireEvent.click(buttonNode);

// Fire event Option 2.
fireEvent(
buttonNode,
new Event('MouseEvent', {
bubbles: true,
cancelable: true,
button: 0,
});
buttonNode,
new MouseEvent('click', {
bubbles: true,
cancelable: true,
Copy link
Member

@timdeschryver timdeschryver Feb 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix, though I would like to re-add the button property.

Suggested change
cancelable: true,
cancelable: true,
button: 0

button is a valid event property - https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button - and it's also implemented like this in fireEvent - https://github.com/testing-library/dom-testing-library/blob/main/src/event-map.js#L82.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pppp606 is correct. There is no button property on Event. It is implemented on MouseEvent.
https://codesandbox.io/s/event-property-button-p6w8xh?file=/src/index.test.js

button: 0,
})
);

expect(buttonNode).toHaveTextContent('1');
expect(cb).toHaveBeenCalledTimes(1);
Expand Down