blakeembrey / blakeembrey/simulate-event
Simulating with overrides throws for read-only properties
- Dominant language
- JavaScript
- Stars
- 24
- Forks
- 9
- PR merge metrics
- No merged PRs in 30d
Description
Howdy! I'm trying to simulate an ENTER keyup event using PhantomJS, but running into an exception:
```js
simulateEvent.simulate(el, 'keyup', { keyCode: 13 })
// => TypeError: Attempting to change value of a readonly property.
```
The `keyCode` property is read-only (as per the [spec](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode)), and when `Object.defineProperty` gets called with the specified override, the above exception is thrown.
I'd be happy to submit a PR, but I'm not quite sure if the fix is preferable [here](https://github.com/blakeembrey/simulate-event/blob/56196882e66d0f7d033de4c71e99cef724b2adb1/simulate-event.js#L333-L346) or [here](https://github.com/blakeembrey/simulate-event/blob/56196882e66d0f7d033de4c71e99cef724b2adb1/simulate-event.js#L401-L406). It seems to me that we basically need to fall back to specifying all the overrides directly at construction time, but I'm not familiar enough with the event construction to know whether that belongs further up or further down.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the PhantomJS keyup example in simulate-event.js, then inspect the Object.defineProperty paths at lines 333-346 and 401-406. Compare event construction with override application and verify that simulating with keyCode: 13 no longer throws for the read-only property.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100