Passing a `MouseEvent` as the arg to `simulate('click', ...)` doesn't maintain properties
- Dominant language
- JavaScript
- Stars
- 19.8k
- Forks
- 2k
- PR merge metrics
- No merged PRs in 30d
Description
# Current behavior
When using `wrapper.simulate('click')` the Synthetic event does not contain default `MouseEvent` properties, like `button`. This is okay since simulate is a generic method.
However, I created a `MouseEvent` object, and attempt to pass this as the second argument to `simulate`, to ensure the expected `MouseEvent` properties are populated, but none of them are.
Passing a simple object with only the `button`, and `buttons` properties, the props are correctly passed through to the onClick handler.
Doesn't work:
```ts
it.each(testTabs)(`Should render each tab when clicked %o`, tab => {
const mouseEvent: MouseEvent = new MouseEvent("click", {
button: 0,
buttons: 1
});
wrapper.find(`a[href="${baseRoute}${tab.relativePath}"]`).simulate("click", mouseEvent);
expect(wrapper.contains(`${tab.title} Content`)).toBeTruthy();
});
```
Works:
```ts
it.each(testTabs)(`Should render each tab when clicked %o`, tab => {
wrapper.find(`a[href="${baseRoute}${tab.relativePath}"]`).simulate("click", { button: 0, buttons: 1 });
expect(wrapper.contains(`${tab.title} Content`)).toBeTruthy();
});
```
### Expected behavior
If I pass a real `MouseEvent` object as arg to the `simulate('click', ...)` that properties from the `MouseEvent` should be passed through to the invoked handler.
### Your environment
Win 10 18363.778, Webpack 4.42.1, Jest 25.4.0, using jsDOM.
#### API
- [ ] shallow
- [X] mount
- [ ] render
#### Version
| library | version
| ------------------- | -------
| enzyme | 3.11.0
| react | 16.13.1
| react-dom | 16.13.1
| react-test-renderer | 16.13.1
| adapter (below) | 1.15.2
#### Adapter
- [X] enzyme-adapter-react-16
- [ ] enzyme-adapter-react-16.3
- [ ] enzyme-adapter-react-16.2
- [ ] enzyme-adapter-react-16.1
- [ ] enzyme-adapter-react-15
- [ ] enzyme-adapter-react-15.4
- [ ] enzyme-adapter-react-14
- [ ] enzyme-adapter-react-13
- [ ] enzyme-adapter-react-helper
- [ ] others ( )
Contributor guide
Assessment
This issue has not been assessed yet.