You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Jest does not call event handler in ForwardRef component when using Preact.
This behavior does not happen in both of the following cases:
I use React in place of Preact and I keep ForwardRef in my component.
I use Preact and I don't use ForwardRef in my component.
It seems the onChange event does not trigger at all in tests while using forwardRef because I never reach it, even when putting a breakpoint directly inside the event:
...
<input // <-- breakpoint here does trigger
type="date"
value={value}
id="test-id"
onChange={e => {
storeValue(e); // <-- breakpoint here does not trigger
}}
ref={ref as Ref<HTMLInputElement>}
/>
...
It occurs even when the forwardRef is used in the tested module like this, e.g. not referencing the tested component and not even imported in the tests at all:
This is an issue with preact-testing-library. It does not translate event names to React version when preact/compat is imported. I will submit a fix there.
I am using Preact 10.19.6 (should be the latest).
The bug
Jest does not call event handler in ForwardRef component when using Preact.
This behavior does not happen in both of the following cases:
It seems the onChange event does not trigger at all in tests while using forwardRef because I never reach it, even when putting a breakpoint directly inside the event:
To Reproduce
Preact repo where you can see the error: https://github.com/DanielMaczak/testing-jest-forwardref-bug
React repo where the test passes: https://github.com/DanielMaczak/testing-react-forwardref-bug
I did my best to make both as close to each other as possible:
Steps to verify the behavior (in both repos):
npm i
npm run test
You will see that one of the repos throws error on the mocked function not being called once while the other does not complain and the test passes.
Expected behavior
Both repos use the same code for the component and for the test, thus results in both should be the same.
The text was updated successfully, but these errors were encountered: