We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
eventWrapper
preact-testing-library
preact
node
npm
yarn
Relevant code or config
// fails: import React from "preact/compat"; import { act, render, fireEvent } from "@testing-library/preact"; // works: // import React from "react"; // import { act, render, fireEvent } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; function ComboBox() { let inputRef = React.useRef(); let buttonProps = { onMouseDown: (e) => { e.preventDefault(); }, }; return ( <div> <input ref={inputRef} /> <button {...buttonProps} /> </div> ); } test("test", () => { const { getAllByRole, queryByRole } = render(<ComboBox />); let button = queryByRole("button"); let combobox = queryByRole("combobox"); expect(document.activeElement).toBe(document.body); act(() => { userEvent.click(button); }); expect(document.activeElement).toBe(document.body); });
What you did:
Call preventDefault on an onMouseDown event to (among other things) prevent the button being focused.
preventDefault
onMouseDown
What happened:
preventDefault() doesn't prevent focussing.
preventDefault()
Problem description:
Behaves differently compared to a browser.
Suggested solution:
The eventWrapper is async,
preact-testing-library/src/pure.js
Lines 13 to 19 in d63da1c
unlike react-testing-library: https://github.com/testing-library/react-testing-library/blob/693228ce10f23e2b695730ea88dbdaa35506e00e/src/pure.js#L11-L26
react-testing-library
this causes fireEvent.mouseDown to return a promise, breaking @testing-library/user-event:
fireEvent.mouseDown
@testing-library/user-event
https://github.com/testing-library/user-event/blob/986e06aec056a99f26c9b119be78268d9605573a/src/click.js#L65
https://github.com/testing-library/dom-testing-library/blob/65024555ee18bb765ae62fb1ba9cf4e6dc7b9f0c/src/events.js#L6
The text was updated successfully, but these errors were encountered:
Successfully merging a pull request may close this issue.
preact-testing-library
version: 2.0.0preact
version: 10.4.8node
version: 14.10.0npm
(oryarn
) version: Yarn 1.22.5Relevant code or config
What you did:
Call
preventDefault
on anonMouseDown
event to (among other things) prevent the button being focused.What happened:
preventDefault()
doesn't prevent focussing.Problem description:
Behaves differently compared to a browser.
Suggested solution:
The
eventWrapper
is async,preact-testing-library/src/pure.js
Lines 13 to 19 in d63da1c
unlike
react-testing-library
: https://github.com/testing-library/react-testing-library/blob/693228ce10f23e2b695730ea88dbdaa35506e00e/src/pure.js#L11-L26this causes
fireEvent.mouseDown
to return a promise, breaking@testing-library/user-event
:https://github.com/testing-library/user-event/blob/986e06aec056a99f26c9b119be78268d9605573a/src/click.js#L65
https://github.com/testing-library/dom-testing-library/blob/65024555ee18bb765ae62fb1ba9cf4e6dc7b9f0c/src/events.js#L6
The text was updated successfully, but these errors were encountered: