-
Notifications
You must be signed in to change notification settings - Fork 472
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
event.nativeEvent missing attributes after fireEvent #245
Comments
EDIT: this wasn't right. In the codesandbox when I run it in the browser, the nativeEvent doesn't have an offsetX and offsetY property, but they still show up in the DOM. Is this the same behavior you see? |
@bcarroll22 yes. I haven't used codesandbox much but it seems kinda flaky. When I run it locally both the console log and resulting DOM do contain them. |
Got it. Here you go: https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/offsetX offsetX and offsetY are readonly properties. Don't have time to test this right now, but maybe this would work?
I think that would probably allow you to overwrite the readonly event property for your case? |
Using your approach i get a console warning:
I am making a variation of react-vis Highlight, https://github.com/uber/react-vis/blob/master/src/plot/highlight.js#L120 It uses event.nativeEvent.offsetX and event.nativeEvent.offsetY. Candidly I am not sure why it uses nativeEvent or if that is required. Maybe related to the warning? Anyways that might be a bigger and different question though. Can you please show me how to simulate event.nativeEvent? Thanks |
Hmmm... That warning is more likely to be an issue with your application code than test code. Do you have a codesandbox/repo that reproduces this issue? |
Do you have a repro for the synthetic event warning? Related issue: testing-library/react-testing-library#268 The MouseEvent constructor doesn't accept offsetX and offsetY, that's why they don't show up on the event when you provide them. So it's actually not even JSDOM that's preventing it from being set, it's the constructor spec which means there's likely no bug to fix for any library. I noticed react-vis uses Enzyme for testing, and their |
https://codesandbox.io/s/qvw69812r9 sorry I should stop messing with it |
Here's a working version: https://codesandbox.io/s/yv2811x0vj There were a few problems:
|
Thank you very much |
Copy of testing-library/react-testing-library#342 sinceI think it is more applicable to this repo.
react-testing-library
version: 6.0.4react
version: 16.8.2node
version: 10.14.1npm
version: 6.8.0Relevant code or config:
App.js
App.test.js
What you did:
Test a react component which has event handlers for mouse events
What happened:
Test failed. console.log indicates that the event does not contain a nativeEvent similar to what is present when running in the browser (chrome 73.0.3683.86)
Reproduction:
https://codesandbox.io/s/61ol4lxnvk
Problem description:
console.log from App.handleMouseDown is different when testing vs running in the browser
Suggested solution:
Unknown
Not sure if this is a bug or something I am doing incorrectly. If the second, an example in the docs might be a good addition. Thank you
The text was updated successfully, but these errors were encountered: