diff --git a/src/__tests__/events.js b/src/__tests__/events.js index 5ff0118d..b79cea35 100644 --- a/src/__tests__/events.js +++ b/src/__tests__/events.js @@ -383,6 +383,8 @@ test('assigns read-only target properties', () => { expect(node.scrollWidth).toBe(0) fireEvent.scroll(node, {target: {scrollWidth: 10}}) + + expect(spy).toHaveBeenCalledTimes(1) expect(node.scrollWidth).toBe(10) }) diff --git a/src/events.js b/src/events.js index 1fb960dc..aba4f7b4 100644 --- a/src/events.js +++ b/src/events.js @@ -46,14 +46,13 @@ function createEvent( }) } - const modifiableProperties = {} + // Make read-only properties of events specifiable for tests. Object.keys(targetProperties).forEach(key => { - modifiableProperties[key] = { + Object.defineProperty(node, key, { value: targetProperties[key], writable: true, - } + }) }) - Object.defineProperties(node, modifiableProperties) const window = getWindowFromNode(node) const EventConstructor = window[EventType] || window.Event